Skip to content

in a transaction: TypeError: 'int' object is not callable #415

@snarfed

Description

@snarfed

i saw a handful of these recently during a spike of traffic. prod GAE, python 3.7 runtime, ndb v1.1.1, but looking at the ndb code, i suspect it's still there in head. full stack trace below; more details afterward. also my app's code is open source; here's the app.py line in the stack trace.

Traceback (most recent call last):
...
  File "/srv/app.py", line 567, in post
    self.setup_refetch_hfeed()
  File "/env/lib/python3.7/site-packages/google/cloud/ndb/_transaction.py", line 191, in transactional_inner_wrapper
    propagation=propagation,
  File "/env/lib/python3.7/site-packages/google/cloud/ndb/_transaction.py", line 72, in transaction
    return future.result()
  File "/env/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 190, in result
    self.check_success()
  File "/env/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 137, in check_success
    raise self._exception
  File "/env/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 309, in _advance_tasklet
    self.generator.throw(type(error), error, traceback)
  File "/env/lib/python3.7/site-packages/google/cloud/ndb/_retry.py", line 77, in retry_wrapper
    if not is_transient_error(error):
  File "/env/lib/python3.7/site-packages/google/cloud/ndb/_retry.py", line 120, in is_transient_error
    code = method()
TypeError: 'int' object is not callable

looking at _retry.is_transient_error(), it assumes that the raised exception's code attribute is a method:

method = getattr(error, "code", None)
if method is not None:
code = method()

...but some exceptions have it as a plain attribute instead, eg urllib.error.HTTPError, which my code does raise occasionally, and might be the culprit here. maybe expand the check to if method is not None and callable(method):?

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to 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