django-pydantic-field
django-pydantic-field copied to clipboard
ValidationError when trying to read bad objects in db
Is there a way to disable validation on retrieval? Currently Django will throw a 500 error if I have an object with an invalid schema in the database. Even when calling Model.objects.all().delete() throws a ValidationError. Thanks for any ideas!.
Hey @mihow, I think the easiest workaround here is to use extended schema to support what's missing from the actual data model. This way you'll be able to load and cleanup invalid data (or even simply delete it). Another benefit in this case that your schema will be more close to the reality.
Another approach, which involves migrations, could be to temporarily switch the model's field to plain JSONField, perform some cleanup, then switch back to the SchemaField. AFAIK this should be a cheap operation (without actual database schema migration).
The third one, is to execute cleanup SQL directly, either one-time manual run, or during migrations with migrations.RunSQL. This is the most powerful (and most dangerous) way of mitigation.
Hope this helps!