Skip to content

Fixes for Django 2.1 #6044

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

Merged
merged 1 commit into from
Jul 6, 2018
Merged

Fixes for Django 2.1 #6044

merged 1 commit into from
Jul 6, 2018

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Jun 21, 2018

Needs #6043 also.

@blueyed blueyed mentioned this pull request Jun 21, 2018
@tomchristie
Copy link
Member

Look good. Anyone else?

@rpkilby
Copy link
Member

rpkilby commented Jun 21, 2018

#6043 has been merged - would be great if you could rebase.

"""Django 2.1 uses datetime.timezone.utc

Ref: https://github.com/django/django/pull/9484#issuecomment-399169042"""
return tz.utcoffset(None).total_seconds() == 0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check seems a bit funky. Is there no better way to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - I am also not happy with it.

Asked about in the commit making this necessary: django/django#9484 (comment).

If Django does not change get_default_timezone itself we could also change the test to compare another (the new) "utc" (which is datetime.timezone.utc).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect, I don't think it's incredibly important to block this PR over the test code. It could be improved, but it's not worth blocking.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behaviour here will be restored for Django v2.1b2. So if we can keep this in a separate commit it'll just be a revert at that point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behaviour here will be restored for Django v2.1b2

Did they revert the original PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No code changes AFAIK.
The assumption might be because of https://code.djangoproject.com/ticket/29514 being accepted.

Copy link
Collaborator

@carltongibson carltongibson Jul 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behaviour change was reverted in django/django@2ec151e. I'd drop this and wait for v2.1b2 to remove from allowed failures.

@blueyed
Copy link
Contributor Author

blueyed commented Jun 21, 2018

Should become green now (also master).

Copy link
Member

@rpkilby rpkilby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say let's hold off until we get some kind of response in regards to django/django#9484. Otherwise, looks good to me.

@carltongibson
Copy link
Collaborator

django/django#10081. We'll see what Tim says.

assert file_obj._size == 14
try:
size = file_obj.size
except AttributeError: # before Django 2.1 _size was private

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the relevant change is django/django@a5406fe. I think size would work in older Django versions.

# add, change, delete built in to django
)

if django.VERSION <= (2, 1):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant <.

@rpkilby rpkilby dismissed their stale review June 22, 2018 22:05

Original concern not important.

@rpkilby
Copy link
Member

rpkilby commented Jun 22, 2018

@blueyed - could you push Tim's suggested changes? It would be good to fix the test suite.

@blueyed
Copy link
Contributor Author

blueyed commented Jun 23, 2018

Rebased.

@@ -62,7 +62,8 @@ def test_parse(self):
self.stream.seek(0)
data_and_files = parser.parse(self.stream, None, self.parser_context)
file_obj = data_and_files.files['file']
assert file_obj._size == 14
size = file_obj.size

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for size variable.

@blueyed
Copy link
Contributor Author

blueyed commented Jul 5, 2018

Removed e22fb41. Will require 2.1b2 now.

commit e22fb41c
Author: Daniel Hahler <[email protected]>
Date:   Thu Jun 21 18:45:50 2018 +0200

    Fix TestDefaultTZDateTimeField
---
 tests/test_fields.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

──────────────────────────────────────────────────────────────────────────────────────────────
modified: tests/test_fields.py
──────────────────────────────────────────────────────────────────────────────────────────────
@ tests/test_fields.py:1346 @ def setup_class(cls):
         cls.field = serializers.DateTimeField()
         cls.kolkata = pytz.timezone('Asia/Kolkata')

+    @staticmethod
+    def is_utc(tz):
+        """Django 2.1 uses datetime.timezone.utc
+
+        Ref: https://github.com/django/django/pull/9484#issuecomment-399169042"""
+        return tz.utcoffset(None).total_seconds() == 0.0
+
     def test_default_timezone(self):
-        assert self.field.default_timezone() == utc
+        assert self.is_utc(self.field.default_timezone())

     def test_current_timezone(self):
-        assert self.field.default_timezone() == utc
+        assert self.is_utc(self.field.default_timezone())
         activate(self.kolkata)
         assert self.field.default_timezone() == self.kolkata
         deactivate()
-        assert self.field.default_timezone() == utc
+        assert self.is_utc(self.field.default_timezone())


 @pytest.mark.skipif(pytz is None, reason='pytz not installed')

.travis.yml Outdated
@@ -42,7 +42,6 @@ matrix:

allow_failures:
- env: DJANGO=master
- env: DJANGO=2.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this line for now and we’ll merge. We can add this after the next release. (Which should be the 16th.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removed ac39602.

@rpkilby
Copy link
Member

rpkilby commented Jul 6, 2018

Thanks!

@rpkilby rpkilby merged commit 56967db into encode:master Jul 6, 2018
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants