MarshalX / atproto

The AT Protocol (πŸ¦‹ Bluesky) SDK for Python 🐍

Home Page:https://atproto.blue

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New Invalid Schema error as of Sept 25

dfm opened this issue Β· comments

Thanks for all the work on this library!! πŸŽ‰

I've been using it to run a bsky bot that posts twice daily and everything had been going smoothly until yesterday, when importing atproto started failing with the following Pydantic error:

  File "/home/runner/work/bsky-nycasp/bsky-nycasp/bsky_nycasp.py", line 6, in <module>
    from atproto import Client
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/atproto/__init__.py", line 3, in <module>
    from .firehose import models as firehose_models
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/atproto/firehose/__init__.py", line 3, in <module>
    from atproto.firehose.client import AsyncFirehoseClient, FirehoseClient
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/atproto/firehose/client.py", line 21, in <module>
    from atproto.firehose.models import ErrorFrame, Frame, MessageFrame
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/atproto/firehose/models.py", line 7, in <module>
    from atproto.xrpc_client.models.utils import get_or_create
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/atproto/xrpc_client/models/__init__.py", line 265, in <module>
    load_models()
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/atproto/xrpc_client/models/models_loader.py", line 58, in load_models
    __on_load()
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/atproto/xrpc_client/models/models_loader.py", line 54, in __on_load
    __rebuild_all_models()
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/atproto/xrpc_client/models/models_loader.py", line 50, in __rebuild_all_models
    __model.model_rebuild()
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/pydantic/main.py", line 470, in model_rebuild
    return _model_construction.complete_model_class(
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 498, in complete_model_class
    cls.__pydantic_core_schema__ = schema = validate_core_schema(schema)
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/pydantic/_internal/_core_utils.py", line 631, in validate_core_schema
    return _validate_core_schema(schema)
pydantic_core._pydantic_core.SchemaError: Invalid Schema:
definitions.definitions.48.model.schema.model-fields.fields.parent.schema.default.schema.nullable.schema.default.schema.tagged-union.choices.`app.bsky.feed.defs#threadViewPost`
  Recursion error - cyclic reference detected [type=recursion_loop, input_value={'type': 'model', 'cls': ...iewPost:94259874186816'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.4/v/recursion_loop
definitions.definitions.48.model.schema.model-fields.fields.replies.schema.default.schema.nullable.schema.list.items_schema.tagged-union.choices.`app.bsky.feed.defs#threadViewPost`
  Recursion error - cyclic reference detected [type=recursion_loop, input_value={'type': 'model', 'cls': ...iewPost:94259874186816'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.4/v/recursion_loop

I've tested v0.0.26 and v0.0.28 and both seem to consistently fail. FWIW, my code runs on GitHub Actions with a fresh environment and installation of atproto every day.

I'm not totally sure how to diagnose or debug this issue, so any pointers would be much appreciated! Thanks!

Hi! Could you pls share the code a little bit? My firehose consumer (custom feed) works great without problems. How can I reproduce? Do you mean it crashes right after "import atproto"? Could you reproduce it in the terminal? pls run this command: python -c "import atproto; print(atproto.__version__)".

recently new pydantic version has been released. maybe that's a problem... try to downgrade pydantic from 2.4 to 2.3

Yes, I can confirm. The problem is new pydantic's update. I have no idea why it starts raising exceptions

btw release yesterday
image

pls use pip install pydantic==2.3 as temp workaround

I created the corresponding issue in pydantic's repo: pydantic/pydantic#7638. Let's wait for the answer first

I've also just confirmed that downgrading Pydantic fixed my workflow. Thanks!!

I'm happy to close this thread as fixed for me, or you can keep it open to track the issue.

Thanks again!

(btw here's my code: https://github.com/dfm/bsky-nycasp)

fixed in pydantic v2.4.1