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 #30128 -- Fixed handling timedelta timezone in database functions. #10910

Merged
merged 1 commit into from Jun 13, 2019

Conversation

cansarigol
Copy link
Contributor

@cansarigol cansarigol commented Jan 28, 2019

Ticket: #30128

if '+' in tzname:
tzname = tzname.split('+')[0]
elif '-' in tzname:
tzname = tzname.split('-')[0]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

after that, I want to add a code block whose purpose is to convert the string to time. Is there another way to solve this?

@timgraham
Copy link
Member

Does one test cover all the new code? Oracle also needs to be addressed. Possibly add something to the 3.0 release notes under "Database backend API" about how third party databases need to adapt.

@cansarigol cansarigol changed the title Fixed #30128 -- Fixed timedelta for extract db model functions (myssql, postgresql, sqlite3) Fixed #30128 -- Fixed timedelta for extract db model functions (myssql, postgresql, sqlite3, oracle) Feb 12, 2019
@timgraham timgraham changed the title Fixed #30128 -- Fixed timedelta for extract db model functions (myssql, postgresql, sqlite3, oracle) Fixed #30128 -- Allowed using a timedelta timezone for extract db functions. Feb 14, 2019
Copy link
Member

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

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

Bar release note change, looks OK I think.

buildbot, test on oracle.

@@ -213,6 +213,15 @@ backends.

* ``DatabaseIntrospection.get_field_type()`` may no longer return tuples.

* ``DatabaseOperations._prepare_tzname_delta()`` is used to customize the database spesific time zone delta function.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this block quite makes sense as it is: _prepare_tzname_delta() is a private helper used only in the already private _convert_field_to_tz() — there's no guarantee at all that a backend will implement either. (The SQLite backend doesn't, for example...)

Maybe just something like:

Supported database backends now correctly handle ``timezone`` formats when
created using `timedelta` instances:

>>> from datetime import timezone, timedelta
>>> str(timezone(timedelta(hours=5)))
'UTC+05:00'

Third-party backends should ensure that they correctly handle this format when
preparing ``datetime`` fields in ``datetime_cast_date_sql()`` & co.

(@felixxm, @timgraham?)

Docs should be wrapped to 79 chars.

@carltongibson
Copy link
Member

New test fails on Oracle.

@cansarigol
Copy link
Contributor Author

cansarigol commented Feb 28, 2019

I had checked on Oracle. I've checked again and I can see that the test is successful. Could you share something with me to create your env on my test env

@charettes
Copy link
Member

@cansarigol it fails with ORA-01882: timezone region not found on CI and with the same error when run locally.

@carltongibson
Copy link
Member

Time to call in the fire service... 🚒

@felixxm: ORACLE ISSUE. PING. 😀

@cansarigol
Copy link
Contributor Author

@cansarigol it fails with ORA-01882: timezone region not found on CI and with the same error when run locally.

I use OracleVM and I guess it is a version problem. I use orcl12c

@cansarigol
Copy link
Contributor Author

I found this page, maybe would be helpful. https://community.oracle.com/thread/841802

Copy link
Member

@timgraham timgraham left a comment

Choose a reason for hiding this comment

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

As I tried to suggest in a previous comment, test coverage doesn't seem sufficient. I think the '-' in tzname: branches aren't tested.

time_delta_params = {}
for attr in {'second', 'minute', 'hour', 'millisecond'}:
if hasattr(_offset_date, attr):
time_delta_params["%ss" % attr] = _offset_date.__getattribute__(attr)
Copy link
Member

Choose a reason for hiding this comment

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

getattr() rather than calling a dunder method

@felixxm
Copy link
Member

felixxm commented Feb 28, 2019

@carltongibson I'll check in next few hours 🕵️‍♂️ , but Oracle version shouldn't be an issue.

@cansarigol
Copy link
Contributor Author

As I tried to suggest in a previous comment, test coverage doesn't seem sufficient. I think the '-' in tzname: branches aren't tested.

I added the test_operations in mysql so far. Is it ok? I can add tests for all backends and all operations funcs (datetime_extract_sql, datetime_trunc_sql etc.) and also sqlite3.base. we can publish with ref commit @timgraham

@carltongibson
Copy link
Member

@cansarigol I think the point is to include them here first time, rather than later. Any reason not to do that?
(Sorry, I missed that part of your earlier comment Tim.)

@timgraham
Copy link
Member

I didn't expect a low-level test. Is testing extract with, e.g. timedelta(hours-5) insufficient?

@cansarigol
Copy link
Contributor Author

@cansarigol I think the point is to include them here first time, rather than later. Any reason not to do that?
(Sorry, I missed that part of your earlier comment Tim.)

Sorry i couldn't understand that "include them" 😀

@cansarigol
Copy link
Contributor Author

I didn't expect a low-level test. Is testing extract with, e.g. timedelta(hours-5) insufficient?

Sorry, you are right I added it for negative timedelta. there was a problem on sqlite3 and I could fix it through the test.

@felixxm
Copy link
Member

felixxm commented Feb 28, 2019

Oracle failure is a great mystery for me, at least for now 🕵️‍♂️. I checked on Oracle 12c, 18c and in the same Oracle DB that we use in Jenkins, all passed without failures. This can be related with some env variables. I need to take a closer look ... 🔍

@cansarigol
Copy link
Contributor Author

hi @felixxm did you have a chance to take a look? and is there any problem with the second commit?
Thanks

@felixxm
Copy link
Member

felixxm commented Mar 28, 2019

@cansarigol Please send a fix to the 28373 as a separate PR, it is harder to trace fixes for multiple tickets in a single PR. Can you also rebase this branch from master and fix conflicts?

@cansarigol cansarigol force-pushed the ticket-30128 branch 2 times, most recently from a1bd9db to e2e6f6f Compare March 28, 2019 13:19
@cansarigol
Copy link
Contributor Author

hi, commits are separated and rebased.

@auvipy
Copy link
Contributor

auvipy commented Apr 6, 2019

sqlite failures related?

@cansarigol
Copy link
Contributor Author

as i remember, it is unrelated. We just have problem about oracle tests.

@felixxm
Copy link
Member

felixxm commented Apr 8, 2019

@cansarigol Please rebase from master and resolve conflicts, after that I will take another round.

@cansarigol
Copy link
Contributor Author

@cansarigol Please rebase from master and resolve conflicts, after that I will take another round.

ok I will

Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

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

@cansarigol I left few comments.

django/db/backends/mysql/operations.py Outdated Show resolved Hide resolved
django/db/backends/sqlite3/base.py Outdated Show resolved Hide resolved
django/db/backends/sqlite3/base.py Outdated Show resolved Hide resolved
tests/db_functions/datetime/test_extract_trunc.py Outdated Show resolved Hide resolved
django/db/backends/sqlite3/base.py Outdated Show resolved Hide resolved
docs/releases/3.0.txt Outdated Show resolved Hide resolved
@felixxm felixxm changed the title Fixed #30128 -- Allowed using a timedelta timezone for extract db functions. Fixed #30128 -- Fixed handling timedelta timezone in database functions. Jun 13, 2019
@felixxm felixxm merged commit fde9b7d into django:master Jun 13, 2019
@claudep
Copy link
Member

claudep commented Jun 13, 2019

Sorry, late to the party, but is there a reason _prepare_tzname_delta wasn't added in the BaseDatabaseOperations class?

@felixxm
Copy link
Member

felixxm commented Jun 13, 2019

It is a part of internal API that is not implemented for all backends and it is used only in _convert_field_to_tz() that is also a part on internal API that is not implemented for all backends.

@claudep
Copy link
Member

claudep commented Jun 13, 2019

Thanks for explaining!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants