Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The to_dict method creates invalid output. It uses mangled field names instead of the original proto field names. #2016

Open
Ark-kun opened this issue Apr 24, 2024 · 0 comments
Assignees

Comments

@Ark-kun
Copy link

Ark-kun commented Apr 24, 2024

Code:

from google.cloud.aiplatform_v1 import Citation
Citation.to_dict(Citation())
                 {
                   "start_index": 0,
                   "end_index": 0,
                   "uri": "",
                   "title": "",
                   "license_": ""
                 }

Notice how the dictionary uses license_ instead of license.

Proto:
https://github.com/googleapis/googleapis/blob/0179dcc4d2b4d7376e7f0292b15c72aab3100dd6/google/cloud/aiplatform/v1beta1/content.proto#L295

The correct proto field name is license.

// Source attributions for content.
message Citation {
  // Output only. Start index into the content.
  int32 start_index = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. End index into the content.
  int32 end_index = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Url reference of the attribution.
  string uri = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Title of the attribution.
  string title = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. License of the attribution.
  string license = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Publication date of the attribution.
  google.type.Date publication_date = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

Generated class:
https://github.com/googleapis/python-aiplatform/blob/c56dd50310ecc42d6a3b0cd2f30db71e8cad0cf6/google/cloud/aiplatform_v1/types/content.py#L536C1-L581C1

class Citation(proto.Message):
    r"""Source attributions for content.

    Attributes:
        start_index (int):
            Output only. Start index into the content.
        end_index (int):
            Output only. End index into the content.
        uri (str):
            Output only. Url reference of the
            attribution.
        title (str):
            Output only. Title of the attribution.
        license_ (str):
            Output only. License of the attribution.
        publication_date (google.type.date_pb2.Date):
            Output only. Publication date of the
            attribution.
    """

    start_index: int = proto.Field(
        proto.INT32,
        number=1,
    )
    end_index: int = proto.Field(
        proto.INT32,
        number=2,
    )
    uri: str = proto.Field(
        proto.STRING,
        number=3,
    )
    title: str = proto.Field(
        proto.STRING,
        number=4,
    )
    license_: str = proto.Field(
        proto.STRING,
        number=5,
    )
    publication_date: date_pb2.Date = proto.Field(
        proto.MESSAGE,
        number=6,
        message=date_pb2.Date,
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants