-
-
Notifications
You must be signed in to change notification settings - Fork 300
Add django 2.0 support #318
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #318 +/- ##
==========================================
+ Coverage 87.75% 87.98% +0.22%
==========================================
Files 33 33
Lines 2483 2471 -12
==========================================
- Hits 2179 2174 -5
+ Misses 304 297 -7
Continue to review full report at Codecov.
|
ab81d04 to
df17d57
Compare
tox.ini
Outdated
| django200: Django ~= 2.0b1 | ||
| djangomaster: https://github.com/django/django/archive/master.tar.gz | ||
| postgres: psycopg2 | ||
| pip_pre = True |
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.
This will not be required once django 2.0 comes out. Also, the line above will need to change to Django ~= 2.0.0
EDIT: If django 2.0 is released before this branch is merged, I'll fix this in a rebase.
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.
This can be updated to Django 2.0rc1
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.
We can now:
- remove
pip_preline django200: Django >= 2.0, < 2.1
|
I'm not able to reproduce the python 2.7 failure locally, unfortunately, so I'd appreciate any insight on the matter. |
vdboor
left a comment
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.
great work, thanks a lot!
The add_media() needs some improvement, the rest looks ok!
polymorphic/compat.py
Outdated
| @@ -0,0 +1,10 @@ | |||
| import django | |||
|
|
|||
| DJANGO_GTE_2 = django.VERSION >= (2, 0) | |||
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'd place django.VERSION >= (2, 0) or even better: django.VERSION < (2, 0) directly inline in the code
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.
Sure ok. WRT this and your other comment in this compat file, please excuse me, I was working on habit here. I've found that it's helpful to have a single point of reference for compatibility hacks, as it makes maintenance easier down the road. I probably shouldn't have introduced it here without running it past you first though :)
I'll move this inline, as you have suggested.
polymorphic/compat.py
Outdated
| from django.urls import URLResolver | ||
| except ImportError: | ||
| # Django < 2.0 | ||
| from django.urls import RegexURLResolver as URLResolver |
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.
There is only a single place where this import is needed. Does that quality for a separate file to do this?
tox.ini
Outdated
| django200: Django ~= 2.0b1 | ||
| djangomaster: https://github.com/django/django/archive/master.tar.gz | ||
| postgres: psycopg2 | ||
| pip_pre = True |
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.
This can be updated to Django 2.0rc1
|
|
||
| class Meta: | ||
| abstract = True | ||
| base_manager_name = "objects" |
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.
do we need a default_manager_name too?
polymorphic/models.py
Outdated
| class Meta: | ||
| abstract = True | ||
| base_manager_name = "objects" | ||
| if not DJANGO_GTE_2: |
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.
if django.VERSION < (2, 0) would be clean here too.
| dest.add_css(media._css) | ||
| dest.add_js(media._js) | ||
| if DJANGO_GTE_2: | ||
| dest += media |
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.
dest object so it will break. Returning dest and updating polymorphic/admin/inlines.py, polymorphic/formsets/models.py would be better.
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.
Are you 100% sure this fails? I thought I had tested this quite thoroughly.
If you're sure you'd like this to change, please confirm, and I'll get it done.
|
I also have a branch I've started on my own at https://github.com/develtech/django-polymorphic/tree/django-2.0. I'm going to consider closing #327 and #328 in favor of moving this one along. |
| env: TOXENV=py35-django111 | ||
| - python: "3.6" | ||
| env: TOXENV=py35-django200 | ||
| - python: "3.6" |
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.
LGTM
|
@meshy Can you swing around to removing the compat module/inlining version checks? |
|
https://travis-ci.org/django-polymorphic/django-polymorphic/jobs/300629621 I don't know where that is coming from. Here's the recreation: Everything greenlights except for Python 2.7 + Django 1.11 Response: |
|
Is the ID of the model an important detail to test against when using defer()? https://docs.djangoproject.com/en/1.11/ref/models/querysets/#django.db.models.query.QuerySet.defer It is strange that id isn't acting as expected. I got no idea where that's coming from. Flipping around sqlite addresses: Changed nothing. It doesn't seem to be anything related to secondary db (same result happens if second db removed from settings). I also ruled out it being due to other tests inside the same class (which shouldn't matter anyway if its in a I'm not sure if the ID is as important as the field showing up deferred. |
|
OK, I've ruled out the above error not being related to this PR, it started here 80b4f2b. So other than the bikeshed stuff (removing the compat file, updating versions and the |
|
@tony thank you for the investigation into the failing test. It's a great relief to know that the cause does not stem from this PR. |
|
I've made most of the requested changes here, and have rebased the commits. Still waiting on a confirmation on the changes requested to I realise it's taken me quite a while to get back to this one -- thank you for your patience! |
|
This is blocked because of failing tests. I believe the issue is in the |
|
The fix in #322 is merged! Sorry for the delay. Would this clear the way for Django 2.0 now? You may want to try rebasing the branch |
Because the URL mechanism has changed in Django 2.0, the RegexURLResolver has been renamed.
The old format was deprecated in Django 1.9, and removed in Django 2.0. Ref: https://docs.djangoproject.com/en/stable/releases/1.9/#passing-a-3-tuple-or-an-app-name-to-include
Neither `add_css` nor `add_js` exist in Django 2.0 because the method for adding `Media` classes together has changed. Ref: django/django@c19b56f
This silences one instance of the warning that's being printed in tests for versions of Django before 2.0: > RemovedInDjango20Warning: Managers from concrete parents will soon > qualify as default managers if they appear before any other managers > in the MRO.
|
Thanks for merging that. I'm still getting that one test failure, but I should be able to investigate it now. It's frustrating that I'm not getting the failure in local tests; only on Travis. |
|
@tony did you get to the bottom of what might be causing the issue? |
|
(I have a lot on my plate ATM, and am not using django-polymorphic in my sites anymore.) I think that deferred issue started happening in 80b4f2b. I don't think it's related to this PR. I notice that in https://github.com/django-polymorphic/django-polymorphic/blob/80b4f2bb41423d6131e2e39ef5c6b212ce5a7b56/polymorphic/tests/test_orm.py#L232, the asserts weren't updated to be wrapped in repr. |
|
See #332 for the last test failure. But I think this PR is ok. |
|
@tony thank you for taking the time to help out here, especially given you've no projects using this library. I quite understand. That looks like a great place for me to dig in. Thanks again! |
Sometimes the tests failed because these objects had IDs that differed from expectations. As the IDs are not relevant to this test, I have replaced the exact string match with a regex match that accepts any ID.
| '<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField), deferred[field1]>') | ||
| self.assertEqual(repr(objects_deferred[3]), | ||
| '<Model2D: id 4, field1 (CharField), field2 (CharField), field3 (CharField), field4 (CharField), deferred[field1]>') | ||
| self.assertRegex(repr(objects_deferred[0]), |
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.
Honestly, this could really be an assertQuerySetEqual, which is more future-proof, and quite cleaner.
Not a blocker for this specific PR though.
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'm not really sure how I would make that change. Thanks for not blocking on it!
|
Tests now appear to be passing! |
vdboor
left a comment
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.
Wow, this change is really getting in the right shape!
The only nagging thing that remains is the add_media performance hack. The proposed solution does break in Django 2.0.
| dest.add_css(media._css) | ||
| dest.add_js(media._js) | ||
| if django.VERSION >= (2, 0): | ||
| dest += media |
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.
This will break. The Django code for dest += does the following:
def __add__(self, other):
combined = Media()
combined._js = self.merge(self._js, other._js)
combined._css = {
medium: self.merge(self._css.get(medium, []), other._css.get(medium, []))
for medium in self._css.keys() | other._css.keys()
}
return combined
Thus, the dest object that was passed to the function is not changed here, while that was the whole point of the add_media performance boost.
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.
However, that was easy to fix, so I've done that in 9d651a1 :-)
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.
It took me far too long to understand why it didn't work. Thanks for fixing that! :)
|
I'm super happy to see all the collaboration to get this PR working. If one of you guys like to have a commit-bit for this project, you're more then welcome! Just mention it here! Having more people to take up work only seems healthy to me :-) |
|
Kudos to you all for getting Django 2.0 support added! I'm the maintainer for Django REST Framework JSON API (https://github.com/django-json-api/django-rest-framework-json-api), and its test suite relies on django-polymorphic for some polymorphic capable serializers that were added. I'm eagerly awaiting this project's next release so I can push out a Django 2.0 compatible release of DJA. 😄 Nice work! |
This fixes a few minor issues to add support for django 2.0(b1).
I have:
but have not yet dug out compat fixes that were added for it.There is one remaining unaddressed
RemovedInDjango20Warning, but I've had some frustration with it. See https://code.djangoproject.com/ticket/28750TODO: