Description
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()