Support DataJoint 2.x attribute-type spellings (backward compatible with 0.14.x) - #47
Support DataJoint 2.x attribute-type spellings (backward compatible with 0.14.x)#47akshay-jaggi wants to merge 4 commits into
Conversation
…0.14.x
DataJoint 2.0 (2026-02-03) is a rewrite, and three spellings this element uses
no longer work on it:
`dj.schema` removed in favour of `dj.Schema`. Importing the module
raises `AttributeError: module 'datajoint' has no attribute
'schema'` before any table is declared.
`boolean` rejected at declaration: `Unsupported attribute type`.
`enum("x", "y")` the 2.x parser passes double-quoted values through verbatim
and emits invalid SQL, so declaration dies with a MySQL
syntax error.
In this element:
- `dj.schema()` -> `dj.Schema()` in `event.py`, `trial.py`
All three are **backward compatible**. In 0.14.9 `dj.schema` and `dj.Schema`
are the same object, and both `bool` and single-quoted `enum` have always been
accepted. Verified by activating the element against MySQL under datajoint
0.14.9 and 2.3.2.
Applied mechanically with regexes, not by hand. Deliberately does NOT touch
`longblob`, which also needs to change for 2.x but has no 0.14.x-compatible
spelling; that lives on the separate `datajoint-2.x` branch.
On DataJoint 2.x a `longblob` attribute is a raw native column. It declares
cleanly and inserts succeed, but a numpy array written to it is returned as
`bytes`, with no error and no warning:
longblob -> returned type: bytes round-trip OK: False
<blob> -> returned type: ndarray round-trip OK: True
Rewrites all 3 `longblob` attribute declarations to the `<blob>` codec, which
restores 0.14.x serialisation behaviour.
This is 2.x-only and cannot be upstreamed as-is: 0.14.9 rejects `<blob>` with
`Support for Adapted Attribute types is disabled`. It therefore sits on this
branch rather than on `compat-fixes`, which stays installable on both lines.
Also adds a README section explaining what this branch is and how the two
branches relate.
There was a problem hiding this comment.
Pull request overview
This PR updates the element’s DataJoint schema initialization to be compatible with DataJoint 2.x (while remaining compatible with DataJoint 0.14.x), preventing import-time failures on fresh installs that resolve DataJoint 2.x.
Changes:
- Replace
schema = dj.schema()withschema = dj.Schema()inelement_event/event.py. - Replace
schema = dj.schema()withschema = dj.Schema()inelement_event/trial.py.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
element_event/event.py |
Switch schema construction to dj.Schema() to avoid dj.schema import-time AttributeError on DataJoint 2.x. |
element_event/trial.py |
Same schema construction update for DataJoint 2.x compatibility. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for this, and for the report in #48 — the diagnosis there is correct. I'd like to redirect this PR rather than merge it. We are not keeping elements working on both 0.14.x and 2.x. A schema is either There is no other 2.x failure in this element to act as a backstop. After this PR it Remaining work for the full PR
Also raise the DataJoint floor — Please work from the migration guide rather than from this comment — it is the There is no Happy to review the full 2.x PR as soon as you open it. I'd suggest closing this one in |
…oint floor Per https://docs.datajoint.com/how-to/migrate-to-v20/ 's type mapping: smallint->int16, int->int32, float->float32. 2 smallint and 9 float attributes, across event.py and trial.py. Verified against a real MySQL 9.7.1 server under datajoint 2.3.2. requirements.txt: datajoint>=0.13 -> datajoint>=2.3. This branch already carried the <blob> conversion (3 attributes) and dj.schema -> dj.Schema; this commit is the remainder of the migration. No boolean or double-quoted enum in this package. Completes datajoint#48 / datajoint#47.
The upstream maintainer asked for one full-migration branch rather than a compat-fixes/datajoint-2.x split (see the linked issue/PR threads). Both branch names now carry the same content; this documents why and lists the complete scope.
One attribute-type spelling used by this element was removed or changed in
DataJoint 2.x. It has a replacement that works identically on 0.14.x, so this can
go in without waiting on a full 2.x migration.
Why now
DataJoint 2.0.0 shipped 2026-02-03 and 2.3.2 is current.
install_requireshere says
datajoint>=0.13, so a fresh install today resolves 2.x and theelement cannot even be imported:
What this changes
schema = dj.schema()inevent.pyandtrial.pydj.schema→dj.SchemaAttributeErrorat importVerified by activating the element against MySQL under datajoint 0.14.9 and
2.3.2 in turn.
What this deliberately does not change
longblob. It also has to change for 2.x — and much more urgently, becauseunder 2.x a
longblobattribute silently storesstr(array)rather than thearray — but
<blob>is rejected by 0.14.9, so shipping it here would breakcurrent users. It is on a separate branch and written up in the accompanying issue.
Applied mechanically with regexes rather than typed by hand, then reviewed. No
behaviour is changed, only spellings. Happy to reshape or split this however you
prefer.