Skip to content

Conversation

@alexAubin
Copy link

When trying to display a model description, for example just typing res.users, i get this stacktrace:

In [1]: res.users
Out[1]: ---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File /usr/local/lib/python3.10/site-packages/IPython/core/formatters.py:770, in PlainTextFormatter.__call__(self, obj)
    763 stream = StringIO()
    764 printer = pretty.RepresentationPrinter(stream, self.verbose,
    765     self.max_width, self.newline,
    766     max_seq_length=self.max_seq_length,
    767     singleton_pprinters=self.singleton_printers,
    768     type_pprinters=self.type_printers,
    769     deferred_pprinters=self.deferred_printers)
--> 770 printer.pretty(obj)
    771 printer.flush()
    772 return stream.getvalue()

File /usr/local/lib/python3.10/site-packages/IPython/lib/pretty.py:408, in RepresentationPrinter.pretty(self, obj)
    406     meth = cls._repr_pretty_
    407     if callable(meth):
--> 408         return meth(obj, self, cycle)
    409 if (
    410     cls is not object
    411     # check if cls defines __repr__
   (...)
    417     and callable(_safe_getattr(cls, "__repr__", None))
    418 ):
    419     return _repr_pprint(obj, self, cycle)

File /usr/local/lib/python3.10/site-packages/odoo_repl/models.py:329, in ModelProxy._repr_pretty_(self, printer, _cycle)
    326 def _repr_pretty_(self, printer, _cycle):
    327     # type: (t.Any, t.Any) -> None
    328     if self._real is not None and printer.indentation == 0:
--> 329         printer.text(model_repr(self._real))
    330     else:
    331         printer.text(repr(self))

File /usr/local/lib/python3.10/site-packages/odoo_repl/models.py:36, in model_repr(obj)
     33 def model_repr(obj):
     34     # type: (t.Union[ModelProxy, BaseModel]) -> t.Text
     35     """Summarize a model's fields."""
---> 36     if obj._real != None:
     37         obj = util.unwrap(obj)

AttributeError: 'res.users' object has no attribute '_real'

Not sure what's really happening here but a naive workaround is to use getattr(obj, "_real", None) instead of obj._real and the model description then displays correctly

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

Successfully merging this pull request may close these issues.

1 participant