palewire / django-postgres-copy

Quickly import and export delimited data with Django support for PostgreSQL's COPY command
https://palewi.re/docs/django-postgres-copy/
MIT License
180 stars 48 forks source link

Add checks for depreciated attributes. #200

Closed geoffrey-eisenbarth closed 1 month ago

geoffrey-eisenbarth commented 1 month ago

Fixes #198. Passed tests both for Django 4.2.14 and 5.1.1 (with the additional change that MockObject.Meta.index_together is replaced with model.Index(fields=["name", "number"])).

palewire commented 1 month ago

Thanks for this. I'm bumping our tests to run against 5.1 too.

palewire commented 1 month ago

Would you mind adding your MockObject trick yet too? I suspect it will then pass the tests and we can merge.

geoffrey-eisenbarth commented 1 month ago

Would you mind adding your MockObject trick yet too? I suspect it will then pass the tests and we can merge.

Is there a straightforward way to use the original MockObject (with index_together) when testing against Django < 5.1 and use a different object (with model.Index) for >= 5.1?

Or should we just update MockObject to use model.Index (which would pass on earlier versions of Django, but not cover the situation where index_together is actually used).

palewire commented 1 month ago

Could this help you do the first?

import django django.get_version()

geoffrey-eisenbarth commented 1 month ago

It's not the cleanest, imo, since we have to override models.Model.__init__(), but I think that's necessary until you decide to drop support for Django < 5.1.