Skip to content
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

Fixed #26348 -- Added TruncTime and exposed it through the __time lookup. #6744

Merged
merged 4 commits into from Jul 8, 2016

Conversation

charettes
Copy link
Member

@charettes charettes commented Jun 8, 2016

@@ -616,6 +619,61 @@ that deal with date-parts can be used with ``DateField``::
2016-01-01 00:00:00+11:00 1
2014-06-01 00:00:00+10:00 1

.. versionadded:: 1.11
Copy link
Member

Choose a reason for hiding this comment

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

These annotations go below the headings.

@jarshwah
Copy link
Member

Just letting you know I do have this in my queue, but just don't have time right now. Will try and have a look during the week.

What were your plans regarding Oracle? Were you looking for advice on how to tackle it, or help from someone with access to an Oracle database?

@charettes
Copy link
Member Author

No worries Josh, it's targeting 1.11 as a new feature anyway I just wanted to get familar with the internals of Trunc and friends.

I should be able to add Oracle support in the next few days, I've got the VM setup locally. I just didn't feel like firing it up before getting any input from your side.

@jarshwah
Copy link
Member

Without going into a lot of detail it looks reasonably good to me. The only concern is really with something that I began - "not a DateField or DateTimeField or TimeField" seems messy from a user perspective, even though it simplifies the code. If there's a nice way to avoid this kind of error without duplicating code everywhere I think that'd be worthwhile.

Will give it a better review this week sometime.

@charettes charettes force-pushed the ticket-26348 branch 2 times, most recently from de8b92c to cf5f81b Compare June 19, 2016 13:11
with less precision. ``expression`` can have an ``output_field`` of either
``TimeField`` or ``DateTimeField``.

Since ``TimeField``\s don't have a time component, only ``Trunc`` subclasses
Copy link
Member

Choose a reason for hiding this comment

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

don't have a date component

@charettes
Copy link
Member Author

@jarshwah I'm thinking of fixing the "not a DateField or DateTimeField or TimeField" case in another commit.

@charettes
Copy link
Member Author

charettes commented Jun 19, 2016

The only remaining failure is related to django.db.backends.oracle.operations.DatabaseOperations._convert_field_to_tz stripping sub-seconds by casting to DATE(). This is also an issue with QuerySet.datetimes() but I'm not sure if it's a regression in 1.10.

@jarshwah, @shaib any idea how this could be solved?

@charettes
Copy link
Member Author

77b73e7 looks like the culprit.

@charettes
Copy link
Member Author

Hmm it looks like Oracle timezone conversion always dropped sub-second precision (e74e207#diff-54b46d05e1da568b3cc987c423e00c50R166) and 77b73e7 was just an adjustment to make it behave consistently when USE_TZ=False.

@charettes
Copy link
Member Author

Buildbot, test on oracle.

@jarshwah
Copy link
Member

Yes, I was surprised by the behaviour of the timezone casting too. I think I was meant to come back to it and forgot to do so. Nice to see you've fixed it up, thanks!

@@ -128,6 +128,13 @@ def datetime_cast_date_sql(self, field_name, tzname):
sql = 'TRUNC(%s)' % field_name
return sql, []

def datetime_cast_time_sql(self, field_name, tzname):
# Since `TimeField` are stored as TIMESTAMP where the "date" part
Copy link
Member

Choose a reason for hiding this comment

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

values are stored

@charettes charettes force-pushed the ticket-26348 branch 2 times, most recently from 0f932c7 to a14d563 Compare July 2, 2016 20:31
@@ -194,6 +194,8 @@ Models

* :class:`~django.db.models.ImageField` now has a default
:data:`~django.core.validators.validate_image_file_extension` validator.
* Added support for time truncation to
Copy link
Member

Choose a reason for hiding this comment

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

add blank line above

@timgraham
Copy link
Member

Repeated from last review: Add a mention of the new DatabaseOperations methods in the release notes, similar to DatabaseOperations.time_extract_sql in 1.9.

@charettes
Copy link
Member Author

Repeated from last review: Add a mention of the new DatabaseOperations methods in the release notes, similar to DatabaseOperations.time_extract_sql in 1.9.

Will do, sorry I missed that.

@charettes
Copy link
Member Author

@timgraham, just pushed the missing release notes.

@@ -263,7 +266,12 @@ Backwards incompatible changes in 1.11
Database backend API
--------------------

* ...
* The ``DatabaseOperations.time_trunc_sql()`` method was added to support
Copy link
Member

Choose a reason for hiding this comment

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

I've been using "is" instead of "was".

@@ -263,7 +266,12 @@ Backwards incompatible changes in 1.11
Database backend API
--------------------

* ...
* The ``DatabaseOperations.time_trunc_sql()`` method was added to support
``TimeField`` truncation. It should accept a ``lookup_type`` and
Copy link
Member

Choose a reason for hiding this comment

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

It accepts... and returns...

@charettes charettes merged commit 8a4f017 into django:master Jul 8, 2016
@charettes charettes deleted the ticket-26348 branch July 8, 2016 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants