Thanks to visit codestin.com
Credit goes to github.com

Skip to content

The message constructor is incompatible with message.to_dict and the actual REST API payloads #344

Open
@Ark-kun

Description

@Ark-kun

The message constructor is incompatible with message.to_dict (when preserving_proto_field_name is used) and the actual REST API payloads. Meanwhile, .from_json is compatible with .to_json.

Environment details

  • Programming language: 3.7
  • OS: Linux
  • Package version: 1.22.1

Steps to reproduce

from google.cloud import batch_v1

This works:

batch_v1.Job.from_json('{"taskGroups": [{}]}')

This does not work:

batch_v1.Job({"taskGroups": [{}]})
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-145-58ddc394e1ed> in <module>
----> 1 batch_v1.Job({"taskGroups": [{}]})

/opt/conda/lib/python3.7/site-packages/proto/message.py in __init__(self, mapping, ignore_unknown_fields, **kwargs)
    564 
    565                 raise ValueError(
--> 566                     "Unknown field for {}: {}".format(self.__class__.__name__, key)
    567                 )
    568 

ValueError: Unknown field for Job: taskGroups

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions