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
Test against django 1.11(b1) / python 3.6 #271
Conversation
Codecov Report
@@ Coverage Diff @@
## master #271 +/- ##
==========================================
+ Coverage 73.04% 73.04% +<.01%
==========================================
Files 31 31
Lines 2478 2482 +4
==========================================
+ Hits 1810 1813 +3
- Misses 668 669 +1
Continue to review full report at Codecov.
|
The failing check appears to match django ticket 22442. The affected model, |
It would appear that only one test references this model. Because the test appears to relate to manager inheritance, I presume we can go with the solution proposed in the django ticket that suggests manually assigning a name to the I'll give that a shot. |
That seems to have done the trick. The tests now confirm the error outlined in #267. |
This avoids the following error in django 1.11 tests: polymorphic.MRODerived: (models.E005) The field 'id' from parent model 'polymorphic.mrobase3' clashes with the field 'id' from parent model 'polymorphic.mrobase1'. Related to https://code.djangoproject.com/ticket/22442
I did a bisect on django to find the cause of the incompatibility. So far, I have found two troublesome commits.
|
polymorphic/tests/test_orm.py
Outdated
@@ -360,7 +360,11 @@ def test_manytomany_field(self): | |||
# no pretty printing | |||
ModelShow1_plain.objects.create(field1='abc') | |||
ModelShow2_plain.objects.create(field1='abc', field2='def') | |||
self.assertEqual(qrepr(ModelShow1_plain.objects.all()), '<QuerySet [<ModelShow1_plain: ModelShow1_plain object>, <ModelShow2_plain: ModelShow2_plain object>]>') | |||
# repr classnames are not hardcoded in 1.11+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should say "django 1.11" for clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebased
if django.VERSION >= (1, 11): | ||
self.assertEqual(qrepr(ModelShow1_plain.objects.all()), '<PolymorphicQuerySet [<ModelShow1_plain: ModelShow1_plain object>, <ModelShow2_plain: ModelShow2_plain object>]>') | ||
else: | ||
self.assertEqual(qrepr(ModelShow1_plain.objects.all()), '<QuerySet [<ModelShow1_plain: ModelShow1_plain object>, <ModelShow2_plain: ModelShow2_plain object>]>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure about repeating the whole line (I thought it wasn't very DRY), but I noticed that this approach was favoured in other similar parts of this file. If you'd prefer it changed to be more DRY, please let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a nicer way to do this. The qrepr()
function is already a custom invention of our own, to avoid the difference of the queryset __repr__
between Django 1.10 and earlier versions. You could upgrade the qrepr()
instead to behave like Django 1.11 does, and upgrade the tests accordingly. This would remove the if/else all together.
I think this is happening because It was suggested in |
I'm not sure what should be done but I don't think the implementation of @francoisfreitag, any advice? |
From what I read in the code, I think the best way to go would be to remove the custom class PolymorphicModelIterable(ModelIterable):
def __iter__(self):
base_result_objects = super(PolymorphicModelIterable, self).__iter__()
for obj in base_result_objects:
yield obj.get_real_instance() I see some advantages to this approach:
About the explicit class-check, I think Django should check for In the meantime, django-polymorphic can bypass this check overriding the Prefetch I hope that's helpful. If that's unclear, I can try to submit a patch during the week-end? |
That's fantastic, thank you @francoisfreitag. I think I see what you're getting at. I'll see if I can get it working with that, but I might need to take you up on the offer of a patch if I can't get it working. The change to django seems like a good idea to me, and would be quite welcome. Would we also need to override the @vdboor, quite a significant change has been proposed here. As you appear to be the main contributor for this repo -- can we get your go-ahead on this idea? |
Might this mean that we lose some of the efficiencies afforded to us by |
The first version would have lost some of the efficiencies. Would something like this be suitable? class PolymorphicModelIterable(ModelIterable):
def __iter__(self):
base_result_objects = super(PolymorphicModelIterable, self).__iter__()
real_instances = self.queryset._get_real_instances(base_result_objects)
for obj in real_instances:
yield obj IIUC, the first version is more efficient if only a small portion of the results is retrieved, because the code would only fetch objects from the database on demand, versus fetching everything and keeping the results in a cache ( |
hi @meshy: Thanks for providing the pull request for 1.11 changes! I like the idea of using the native iterator functionality of Django. I'd be really happy to see more people taking up maintenance work. Lots changed since I took this up in 2013 (for Django 1.5! compatibility). If you're interestted @meshy, let me know! |
Hi @vdboor! Thanks for the merge I'd like to have a go at getting this working on django 1.11, but I'm not sure I currently have the time to be a maintainer. That said, I'm working on a project that depends on this one, so I still plan to help out when I can |
@francoisfreitag: my preliminary test of your second suggestion is very promising, thank you. It makes django 1.11 pass on all tests (with a little tweaking)! Unfortunately, only django 1.11 passes -- all other versions fail I'll keep investigating, and will open a new PR when I have something worth looking at. |
This issue has been handled in https://code.djangoproject.com/ticket/28096. |
This builds django-polymorphic against python 3.6 and django 1.11b1.
The new version of python works fine, but django 1.11 fails.
The test suite now runs checks, and it seems to be failing on one of them:polymorphic.MRODerived: (models.E005) The field 'id' from parent model 'polymorphic.mrobase3' clashes with the field 'id' from parent model 'polymorphic.mrobase1'.
Once that's addressed, I suspect we're going to get a little closer to the cause of #267.Ok, fixed that, now we're seeing #267.