django-polymorphic
django-polymorphic copied to clipboard
ManyToManyField with through and postgres
Here a branch and one test to show when it breaks: https://github.com/django-polymorphic/django-polymorphic/compare/master...boertel:bug_postgres_many2many?expand=1
WIth sqlite, the following works fine:
$ ./runtests.py polymorphic.tests.test_orm.PolymorphicTests.test_manytomany_with_through_field
But with postgres:
$ pip install psycopg2-binary
$ PRIMARY_DATABASE="postgres://localhost/polymorphic" ./runtests.py polymorphic.tests.test_orm.PolymorphicTests.test_manytomany_with_through_field
it returns the following error:
AssertionError: <RedheadDuck: RedheadDuck object (2)> is not an instance of <class 'polymorphic.tests.models.RubberDuck'>
If it can be any help, I started debugging the stack, and everything is fine (aka the queryset contains the right objects) until it hits:
https://github.com/django/django/blob/59ffafa1d2f466fa7aacbe74fe2787b2004b7871/django/db/models/query.py#L908 after add_q
function, clone
contains wrong objects.
I'm running python 3.7.3, django==2.1.9 and django-polymorphic==2.0.3 (and I branched out from master for my branch)