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

cyclic object references aren't checked, leads to RecursionError #507

Closed
gabroo opened this issue Mar 16, 2022 · 2 comments
Closed

cyclic object references aren't checked, leads to RecursionError #507

gabroo opened this issue Mar 16, 2022 · 2 comments
Assignees
Labels
api: logging Issues related to the googleapis/python-logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@gabroo
Copy link

gabroo commented Mar 16, 2022

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

If you are still having issues, please be sure to include as much information as possible:

Environment details

  • OS type and version: macOS 12.2.1
  • Python version: python --version 3.8.12
  • pip version: pip --version 21.2.4
  • google-cloud-logging version: pip show google-cloud-logging 3.0.0

Steps to reproduce

  1. pip install google-cloud-logging==3.0.0

Code example

from google.cloud.logging import Client
c = Client()
a = {"foo": "bar"}
a["baz"] = a
c.logger("logs").log(a)

Stack trace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/cloud/logging_v2/logger.py", line 245, in log
    self.log_struct(message, client=client, **kw)
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/cloud/logging_v2/logger.py", line 209, in log_struct
    self._do_log(client, StructEntry, info, **kw)
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/cloud/logging_v2/logger.py", line 158, in _do_log
    client.logging_api.write_entries([api_repr])
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/cloud/logging_v2/_gapic.py", line 151, in write_entries
    log_entry_pbs = [_log_entry_mapping_to_pb(entry) for entry in entries]
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/cloud/logging_v2/_gapic.py", line 151, in <listcomp>
    log_entry_pbs = [_log_entry_mapping_to_pb(entry) for entry in entries]
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/cloud/logging_v2/_gapic.py", line 542, in _log_entry_mapping_to_pb
    ParseDict(mapping, entry_pb)
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/protobuf/json_format.py", line 445, in ParseDict
    parser.ConvertMessage(js_dict, message)
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/protobuf/json_format.py", line 476, in ConvertMessage
    self._ConvertFieldValuePair(value, message)
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/protobuf/json_format.py", line 580, in _ConvertFieldValuePair
    self.ConvertMessage(value, sub_message)
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/protobuf/json_format.py", line 474, in ConvertMessage
    methodcaller(_WKTJSONMETHODS[full_name][1], value, message)(self)
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/protobuf/json_format.py", line 666, in _ConvertStructMessage
    self._ConvertValueMessage(value[key], message.fields[key])
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/protobuf/json_format.py", line 633, in _ConvertValueMessage
    self._ConvertStructMessage(value, message.struct_value)
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/protobuf/json_format.py", line 666, in _ConvertStructMessage
    self._ConvertValueMessage(value[key], message.fields[key])
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/protobuf/json_format.py", line 633, in _ConvertValueMessage
    self._ConvertStructMessage(value, message.struct_value)
  File "/usr/local/google/home/sajeevs/miniconda3/envs/test/lib/python3.8/site-packages/google/protobuf/json_format.py", line 666, in _ConvertStructMessage
    self._ConvertValueMessage(value[key], message.fields[key])

[...]

RecursionError: maximum recursion depth exceeded while calling a Python object

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

Thanks!

@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/python-logging API. label Mar 16, 2022
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Mar 17, 2022
@arbrown arbrown assigned arbrown and unassigned daniel-sanche Mar 17, 2022
@arbrown arbrown added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed triage me I really want to be triaged. labels Mar 17, 2022
@arbrown
Copy link
Contributor

arbrown commented Mar 18, 2022

It looks like this is a known issue with the protobuf serialization format used to send log entries to the API. The only surefire solution I can think of would involve rewriting the serialization to do this check for us, and the issue I linked above implies there is little chance of that.

If you need to log such a relationship, you might consider doing so with ids instead of object references:

from google.cloud.logging import Client
c = Client()
a = {"foo": "bar", id: 7}
a["baz_id"] = a.id
c.logger("logs").log(a)

I will close this issue next week, but please let me know if there is a pressing need to log these kinds of cyclic relationships and we can consider looking into it further.

@arbrown arbrown added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Mar 18, 2022
@gabroo
Copy link
Author

gabroo commented Mar 20, 2022

Thanks for looking into it. I didn't look close enough to realize it's a protobuf error. We have no need to log these types of structs but it was something that popped up when writing tests.

@gabroo gabroo closed this as completed Mar 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/python-logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants