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

Invalid type for user_id field returned by TransferConfig.to_dict #240

Closed
mik-laj opened this issue Dec 28, 2020 · 2 comments · Fixed by #267
Closed

Invalid type for user_id field returned by TransferConfig.to_dict #240

mik-laj opened this issue Dec 28, 2020 · 2 comments · Fixed by #267
Assignees
Labels
P2 A nice-to-fix bug type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@mik-laj
Copy link

mik-laj commented Dec 28, 2020

user_id field is deprecated but it still causes us problems. TransferConfig.to_dict creates a dictionary that has the wrong type of this field. This type of this field should be one of: int, long, but this field has type str. This is especially problematic because to_dict method set this field to default value - "0", so I need to convert this field to the correct type on my side.

It would be great if TransferConfig.to_dict returned the correct representation for this object

Environment details

  • OS type and version:
  • Python version: Python 3.6.12
  • pip version: pip 20.2.4
  • google-cloud-bigquery-datatransfer version: google-cloud-bigquery-datatransfer==3.0.0

Steps to reproduce

  1. Run code example

Code example

from google.cloud.bigquery_datatransfer_v1.types import TransferConfig

a = TransferConfig(user_id=123)
b = TransferConfig.to_dict(a)
c = TransferConfig(**b)

Workaround:

from google.cloud.bigquery_datatransfer_v1.types import TransferConfig

a = TransferConfig(user_id=123)
b = TransferConfig.to_dict(a)
# HACK: TransferConfig.to_dict returns invalid representation
b['user_id'] = int(b['user_id'])
c = TransferConfig(**b)

Stack trace

Traceback (most recent call last):
  File "/files/bigquery_dts.py", line 7, in <module>
    c = TransferConfig(**b)
  File "/usr/local/lib/python3.6/site-packages/proto/message.py", line 466, in __init__
    self.__dict__["_pb"] = self._meta.pb(**params)
TypeError: '123' has type str, but expected one of: int, long

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

@mik-laj mik-laj changed the title Invalid type for user_id field after TransferConfig was converted to dictionary. Invalid type for user_id field returned by TransferConfig.to_dict Dec 28, 2020
@tswast tswast transferred this issue from googleapis/python-bigquery-datatransfer Jul 15, 2021
@tswast
Copy link

tswast commented Jul 15, 2021

Moved this to proto-plus as it is responsible for converting to/from dictionaries. I agree that the round-trip should work.

Workaround may be to use to_json and from_json, as that round-trip should work.

Perhaps a from_dict method would actually be useful for going from parsed JSON representation? #152

@tswast tswast removed their assignment Jul 15, 2021
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Jul 15, 2021
@vchudnov-g vchudnov-g added P2 A nice-to-fix bug type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Sep 13, 2021
@software-dov
Copy link
Contributor

This is an unexpected surfacing of the issue fixed by #267
Closing as the fix is now in main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A nice-to-fix bug type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants