Skip to content

printing dsms.buffers.updated leads to circular reference #51

@MBueschelberger

Description

@MBueschelberger

Simply returning dsms.buffers.updated leads to the following traceback:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/.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 ~/.local/lib/python3.10/site-packages/IPython/lib/pretty.py:394, in RepresentationPrinter.pretty(self, obj)
    391 for cls in _get_mro(obj_class):
    392     if cls in self.type_pprinters:
    393         # printer registered in self.type_pprinters
--> 394         return self.type_pprinters[cls](obj, self, cycle)
    395     else:
    396         # deferred printer
    397         printer = self._in_deferred_types(cls)

File ~/.local/lib/python3.10/site-packages/IPython/lib/pretty.py:701, in _dict_pprinter_factory.<locals>.inner(obj, p, cycle)
    699     p.pretty(key)
    700     p.text(': ')
--> 701     p.pretty(obj[key])
    702 p.end_group(step, end)

File ~/.local/lib/python3.10/site-packages/IPython/lib/pretty.py:419, in RepresentationPrinter.pretty(self, obj)
    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)
    421     return _default_pprint(obj, self, cycle)
    422 finally:

File ~/.local/lib/python3.10/site-packages/IPython/lib/pretty.py:794, in _repr_pprint(obj, p, cycle)
    792 """A pprint that just redirects to the normal repr function."""
    793 # Find newlines and replace them with p.break_()
--> 794 output = repr(obj)
    795 lines = output.splitlines()
    796 with p.group():

File /app/dsms/knowledge/kitem.py:262, in KItem.__repr__(self)
    260 def __repr__(self) -> str:
    261     """Pretty print the kitem Fields"""
--> 262     return str(self)

File /app/dsms/knowledge/kitem.py:256, in KItem.__str__(self)
    254 def __str__(self) -> str:
    255     """Pretty print the kitem fields"""
--> 256     return print_model(
    257         self, "kitem", exclude_extra=self.dsms.config.hide_properties
    258     )

File /app/dsms/knowledge/utils.py:47, in print_model(self, key, exclude_extra)
     45 def print_model(self, key, exclude_extra: set = set()) -> str:
     46     """Pretty print the ktype fields"""
---> 47     dumped = dump_model(self, exclude_extra)
     48     return yaml.dump({key: dumped})

File /app/dsms/knowledge/utils.py:66, in dump_model(self, exclude_extra)
     52 """
     53 Dump the model fields into a dictionary format with optional exclusions.
     54 
   (...)
     63     Dict[str, Any]: A dictionary of the model fields with specified exclusions.
     64 """
     65 exclude = self.model_config.get("exclude", set()) | exclude_extra
---> 66 dumped = self.model_dump(
     67     exclude_none=True,
     68     exclude_unset=True,
     69     exclude=exclude,
     70 )
     71 return {
     72     key: (str(value) if isinstance(value, UUID) else value)
     73     for key, value in dumped.items()
     74 }

File /usr/local/lib/python3.10/site-packages/pydantic/main.py:426, in BaseModel.model_dump(self, mode, include, exclude, context, by_alias, exclude_unset, exclude_defaults, exclude_none, round_trip, warnings, serialize_as_any)
    388 def model_dump(
    389     self,
    390     *,
   (...)
    401     serialize_as_any: bool = False,
    402 ) -> dict[str, Any]:
    403     """Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump
    404 
    405     Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
   (...)
    424         A dictionary representation of the model.
    425     """
--> 426     return self.__pydantic_serializer__.to_python(
    427         self,
    428         mode=mode,
    429         by_alias=by_alias,
    430         include=include,
    431         exclude=exclude,
    432         context=context,
    433         exclude_unset=exclude_unset,
    434         exclude_defaults=exclude_defaults,
    435         exclude_none=exclude_none,
    436         round_trip=round_trip,
    437         warnings=warnings,
    438         serialize_as_any=serialize_as_any,
    439     )

ValueError: Circular reference detected (id repeated)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions