Repository navigation
fix(condition): a time key fetched on MySQL restricts its own table - #1765
Open
dimitri-yatsenko wants to merge 3 commits into
Open
dimitri-yatsenko wants to merge 3 commits into
dimitri-yatsenko wants to merge 3 commits into
Conversation
MySQL fetches a time attribute as a datetime.timedelta, which a restriction refused, so a key fetched from a table with a time attribute could not restrict that table, delete by it, or populate below it. A timedelta is now written as [-]HH:MM:SS[.ffffff], with hours past 24 and negative values as MySQL's TIME allows. numpy.timedelta64 values, as in a DataFrame from to_pandas(), are converted first; those without a fixed unit are refused. Fixes #1762.
dimitri-yatsenko
requested review from
MilagrosMarin,
lum-agilyti and
ttngu207
November 28, 2026 05:12
MilagrosMarin
previously approved these changes
Nov 28, 2026
MilagrosMarin
left a comment
Contributor
There was a problem hiding this comment.
Thanks @dimitri-yatsenko, this closes a real gap: a key fetched from a MySQL table with a time attribute now restricts its own table.
What I checked, with master merged in locally:
- Full suite: 2068 passed, 20 skipped, on MySQL and PostgreSQL.
- With master's
condition.pyrestored, 12 of the new tests fail, so they guard the fix. - On MySQL, fetched keys for 8 values (0, 1 µs, 12:34:56.789012, 23:59:59.999999, -1 µs, -25h, 100:00:00.5, 838:59:59) each restrict to exactly 1 row and
-leaves 7;table & table.to_pandas()matches all 8. On PostgreSQL the same holds for the 4 in-day values. dateanddatetime(6)keys still restrict as before on both backends.
Minor points, none blocking:
- A
timedelta64with sub-microsecond precision is silently truncated:np.timedelta64(1500, "ns")matches the row at 1 µs. It may be worth raising or noting this. - On PostgreSQL, a timedelta outside 0..24h reaches the server and comes back as a driver error (
DatetimeFieldOverflowfor 2 days,InvalidDatetimeFormatfor -1 s) rather than aDataJointError. - Not from this PR:
table & table.to_pandas()still fails on adatetimecolumn ("Unsupported value of type datetime64"). Sincetimedelta64is now converted, thedatetime64counterpart could be a small follow-up.
The conflict with #1735 is two neighboring additions in condition.py and the test file; keeping both sides resolves it.
Negative and over-24-hour MySQL values round-tripping through a fetched key was the case I most wanted to see covered, and it is.
…estriction # Conflicts: # src/datajoint/condition.py # tests/integration/test_restriction_values.py
Member
Author
|
Merged master in (08a7bac) after #1735. Both sides kept in each conflict:
Unit tests and |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1762.
Summary
On MySQL, a
timeattribute is fetched as adatetime.timedelta. A restriction by that value raised "Unsupported value of type timedelta", so a key fetched from a table with atimeattribute could not restrict its own table, delete by it, or populate below it.condition.py:make_conditionwrites atimedeltaas aTIMEliteral,[-]HH:MM:SS[.ffffff], computed from its total microseconds. Hours may exceed 24 and the value may be negative, as MySQL'sTIMEallows.str(timedelta)is not used, because'1 day, 2:00:00'is not aTIMEliteral.numpy.timedelta64(the values of atimedelta64DataFrame column, as fromto_pandas()) is converted to atimedeltafirst;NaTrestricts asIS NULL. Atimedelta64without a fixed unit (generic, years, months) is refused.PostgreSQL fetches a
timeattribute asdatetime.time, which was already supported. Atimedeltawithin one day also restricts a PostgreSQLtimeattribute.Tests
New integration tests in
test_restriction_values.py, on MySQL and PostgreSQL:timeandtime(6), as a dict, a list of keys and a DataFrame;reserve_jobs;timedeltavalues against a PostgreSQLtimeattribute;timedelta64values without a fixed unit are refused.populate(reserve_jobs=True)below a nativetimekey is skipped on PostgreSQL: the jobs table cannot yet be declared there (#1763).The full suite passes: 2068 passed, 20 skipped.
This conflicts with #1735 in
condition.pyandtest_restriction_values.py(neighboring lines). Whichever merges second needs master merged in.