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

sqlalchemy_utils generic_repr breaks repr for gino models #16

Open
asfaltboy opened this issue Sep 1, 2020 · 1 comment
Open

sqlalchemy_utils generic_repr breaks repr for gino models #16

asfaltboy opened this issue Sep 1, 2020 · 1 comment

Comments

@asfaltboy
Copy link

While playing around with the gino ORM on the shell, I kept encountering the NoInspectionAvailable error.
Eventually, I traced this back to @generic_repr decorator and removing it fixed the problem.
Here is the full stack trace:

In [1]: from app.settings.globals import ARQ_BACKGROUND_FUNCTIONS, DATABASE_CONFIG
   ...: from app.models.orm.user import User
   ...: from app.application import app, db
   ...: await db.set_bind(DATABASE_CONFIG.url)
   ...: await User.get(1)
Out[1]: -------------------------------------------------
NoInspectionAvailable                     Traceback (most recent call last)
  /my_env/lib/python3.8/site-packages/IPython/core/formatters.py(702)__call__()
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

  /my_env/lib/python3.8/site-packages/IPython/lib/pretty.py(394)pretty()
    392                         if cls is not object \
    393                                 and callable(cls.__dict__.get('__repr__')):
--> 394                             return _repr_pprint(obj, self, cycle)
    395
    396             return _default_pprint(obj, self, cycle)

  /my_env/lib/python3.8/site-packages/IPython/lib/pretty.py(700)_repr_pprint()
    698     """A pprint that just redirects to the normal repr function."""
    699     # Find newlines and replace them with p.break_()
--> 700     output = repr(obj)
    701     lines = output.splitlines()
    702     with p.group():

  /my_env/lib/python3.8/site-packages/sqlalchemy_utils/models.py(89)<lambda>()
     87     if len(fields) == 1 and callable(fields[0]):
     88         target = fields[0]
---> 89         target.__repr__ = lambda self: _generic_repr_method(self, fields=None)
     90         return target
     91     else:

  /my_env/lib/python3.8/site-packages/sqlalchemy_utils/models.py(42)_generic_repr_method()
     40
     41 def _generic_repr_method(self, fields):
---> 42     state = sa.inspect(self)
     43     field_reprs = []
     44     if not fields:

> /my_env/lib/python3.8/site-packages/sqlalchemy/inspection.py(71)inspect()
     69
     70     if raiseerr and (reg is None or ret is None):
---> 71         raise exc.NoInspectionAvailable(
     72             "No inspection system is "
     73             "available for object of type %s" % type_

NoInspectionAvailable: No inspection system is available for object of type <class 'app.models.orm.user.User'>```
@leosussan
Copy link
Owner

Thank you for this! I'm going to update this repo w/ some updates that'll include a fix to this, will check it out.

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