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

Duplicate index hashes for pydantic.main are created when models are returned from FastAPI routes #498

Open
elicore opened this issue Apr 11, 2023 · 0 comments
Labels
bug Something isn't working maintenance

Comments

@elicore
Copy link

elicore commented Apr 11, 2023

FastAPI creates duplicate models that are used as the returned model from a route. It uses the create_model() function from pydantic.main to do that.

When the duplicate models are being created, they are also queued for migrations in the Migrator class, which creates unnecessary keys in redis for the index hashes in the form of {global_prefix}:pydantic.Main.{class_name}:index:hash.

There are a couple of possible workarounds:

Do not use redis-om-python models as return values from FastAPI routes
This option doesn't make a whole lot of sense and will create lots of duplicate code for extra models instead of reusing the redis-om models (as their pydantic base).

Do not use Migrator().run()
Instead, use this piece of code to filter-out the pydantic hashes:

migrator = aredis_om.Migrator()
await migrator.detect_migrations()
for migration in migrator.migrations:
    if not migration.model_name.lower().startswith('pydantic.main'):
        await migration.run()
@chayim chayim added bug Something isn't working maintenance labels Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working maintenance
Projects
None yet
Development

No branches or pull requests

2 participants