{"payload":{"feedbackUrl":"https://github.com/orgs/community/discussions/53140","repo":{"id":30675223,"defaultBranch":"master","name":"apitools","ownerLogin":"google","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2015-02-11T23:27:13.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/1342004?v=4","public":true,"private":false,"isOrgOwned":true},"refInfo":{"name":"","listCacheKey":"v0:1714411184.0","currentOid":""},"activityList":{"items":[{"before":"ac45a78b4f4b0b92615c307d6467314ba407b9eb","after":"41f8feae5172d9cc7d320d0baec4473cd12389f0","ref":"refs/heads/master","pushedAt":"2024-04-29T16:43:01.000Z","pushType":"pr_merge","commitsCount":1,"pusher":{"login":"jameslynnwu","name":"James Wu","path":"/jameslynnwu","primaryAvatarUrl":"https://avatars.githubusercontent.com/u/1021477?s=80&v=4"},"commit":{"message":"Update apitools version to 0.5.34. (#322)","shortMessageHtmlLink":"Update apitools version to 0.5.34. (#322)"}},{"before":"9f424616e611154ef8ca9ddfe7869e1be18cb86a","after":"ac45a78b4f4b0b92615c307d6467314ba407b9eb","ref":"refs/heads/master","pushedAt":"2024-04-29T16:42:49.000Z","pushType":"pr_merge","commitsCount":1,"pusher":{"login":"jameslynnwu","name":"James Wu","path":"/jameslynnwu","primaryAvatarUrl":"https://avatars.githubusercontent.com/u/1021477?s=80&v=4"},"commit":{"message":" Fix JSON encoding of nested message fields corresponding to query params. (#321)\n\n* Add example of a nested message field query param to samples.\r\n\r\n* Fix JSON encoding of nested message fields corresponding to query params.\r\n\r\nNote that apitools already has logic to add custom JSON encodings in the\r\ngenerated messages file for message fields whose names differ from their\r\neventual JSON representations:\r\nhttps://github.com/google/apitools/blob/c7d44d6bef513e82fe2b8740352e5e2290dd2e5c/apitools/gen/extended_descriptor.py#L220-L225\r\nExamples can be found throughout the generated message files, e.g.\r\nhttps://github.com/google/apitools/blob/c7d44d6bef513e82fe2b8740352e5e2290dd2e5c/samples/iam_sample/iam_v1/iam_v1_messages.py#L955-L956.\r\nThis happens here when writing the file:\r\nhttps://github.com/google/apitools/blob/c7d44d6bef513e82fe2b8740352e5e2290dd2e5c/apitools/gen/extended_descriptor.py#L162-L171\r\nSpecifically, in AddDescriptorFromSchema, the ExtendedMessageDescriptor\r\nobjects that are instantiated will contain field_mappings for any field\r\nwhose converted Python attribute name in the message differs from its\r\nname in the discovery doc:\r\nhttps://github.com/google/apitools/blob/c7d44d6bef513e82fe2b8740352e5e2290dd2e5c/apitools/gen/message_registry.py#L278-L281\r\n\r\nThis all works correctly for explicit message types defined in the API\r\nprotos (which end up in the \"schemas\" field of the discovery doc).\r\nHowever, apitools also uses AddDescriptorFromSchema to generate\r\ntop-level request message types (which don't correspond to any\r\nunderlying discovery doc schema message):\r\nhttps://github.com/google/apitools/blob/c7d44d6bef513e82fe2b8740352e5e2290dd2e5c/apitools/gen/service_registry.py#L273\r\nTo do so, it basically creates a schema dictionary on the fly that\r\nmatches the one used in the discovery doc JSON and includes the\r\nproperties for each field, and then passes that to\r\nAddDescriptorFromSchema. The problem is that when creating this\r\npseudo-schema, it determines the field name property for query params by\r\ncalling self.__names.CleanName() on the parameter name:\r\nhttps://github.com/google/apitools/blob/c7d44d6bef513e82fe2b8740352e5e2290dd2e5c/apitools/gen/service_registry.py#L288\r\nBut this means that the field name is already in its converted Python\r\nform when AddDescriptorFromSchema sees it, so the generated field name\r\nmatches the field name passed to it, and no custom field mapping\r\ngets added even if there should be one. In particular, for nested\r\nmessage query params, the JSON parameter will be something like e.g.\r\noptions.requestedPolicyVersion, whereas the Python name will be e.g.\r\noptions_requestedPolicyVersion, so a custom JSON encoding *should* be\r\ngenerated for that field, but isn't (similarly for query params that\r\nconflict with Python keywords e.g. 'continue' <-> 'continue_').\r\n\r\nThe fix here is just deleting the call to self.__names.CleanName() in\r\n__CreateRequestType; AddDescriptorFromSchema already calls that when\r\nconstructing the field\r\n(https://github.com/google/apitools/blob/c7d44d6bef513e82fe2b8740352e5e2290dd2e5c/apitools/gen/message_registry.py#L329-L332)\r\nand thus there's no need to call it ahead of time. This way,\r\nAddDescriptorFromSchema will receive the original JSON parameter name,\r\nand can see that it differs from the generated Python field name,\r\nso it will now add a custom field mapping for any such query param\r\nfields in the request message.\r\n\r\nNote that this bug has been present in apitools for as long as it has\r\nexisted, dating back to the very first version. This has necessitated a\r\nlot of manual calls to encoding.AddCustomJsonFieldMapping() to work\r\naround it in consumers of apitools; these can now all be cleaned up\r\nsince they'll be included in the generated messages file directly. In\r\ntheory this shouldn't break anything either; the behavior already was\r\nbroken and requests would fail without the workaround, and the\r\nworkarounds themselves won't affect anything even if they're not cleaned\r\nup after this fix (it's okay to add a custom JSON field mapping twice as\r\nlong as both mappings are the same:\r\nhttps://github.com/google/apitools/blob/c7d44d6bef513e82fe2b8740352e5e2290dd2e5c/apitools/base/py/encoding_helper.py#L676-L685).","shortMessageHtmlLink":" Fix JSON encoding of nested message fields corresponding to query pa…"}},{"before":"c7d44d6bef513e82fe2b8740352e5e2290dd2e5c","after":"9f424616e611154ef8ca9ddfe7869e1be18cb86a","ref":"refs/heads/master","pushedAt":"2024-04-29T16:42:32.000Z","pushType":"pr_merge","commitsCount":1,"pusher":{"login":"jameslynnwu","name":"James Wu","path":"/jameslynnwu","primaryAvatarUrl":"https://avatars.githubusercontent.com/u/1021477?s=80&v=4"},"commit":{"message":"Update to work with PY3.11. (#320)","shortMessageHtmlLink":"Update to work with PY3.11. (#320)"}}],"hasNextPage":false,"hasPreviousPage":false,"activityType":"all","actor":null,"timePeriod":"all","sort":"DESC","perPage":30,"cursor":"djE6ks8AAAAEPTEdFwA","startCursor":null,"endCursor":null}},"title":"Activity · google/apitools"}