fix(#1438): preserve json flag for MariaDB longtext-aliased columns#1443
Open
dimitri-yatsenko wants to merge 1 commit intomasterfrom
Open
fix(#1438): preserve json flag for MariaDB longtext-aliased columns#1443dimitri-yatsenko wants to merge 1 commit intomasterfrom
dimitri-yatsenko wants to merge 1 commit intomasterfrom
Conversation
MariaDB stores `json` columns as `longtext` and reports them back through information_schema as `longtext`, so the DB-type-based detection in _init_from_database() leaves attr["json"] False. The :json: comment marker written at declare-time survives the aliasing, so recover the json flag from the original declared type alongside the existing UUID recovery. No-op on MySQL/PostgreSQL where the regex match against the DB-reported type already sets attr["json"] = True.
ttngu207
approved these changes
Apr 30, 2026
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.
Summary
Fixes #1438. MariaDB stores
jsoncolumns aslongtextand reports them back throughinformation_schemaaslongtext, so DataJoint's DB-type-based JSON detection inHeading._init_from_database()leftattr["json"]asFalse. That silently broke insert (json.dumpsskipped →dictreaches pymysql →TypeError) and fetch (json.loadsskipped → caller gets the raw string).The
:json:comment marker is already written at declare-time (JSON is inCORE_TYPE_NAMES/SPECIAL_TYPES) and already parsed back intoattr["original_type"]on read. Recoverattr["json"]from that marker in the same block where UUID is already recovered.Behavior by backend
json, regex matches,attr["json"] = Truefrom the existing line. The new branch reasserts the same value — no behavior change.json/jsonb, regex matches both. Same as MySQL — no-op.longtext, regex misses,attr["json"]wasFalse. The:json:comment marker is intact, socategory == "JSON"and the new branch flips it toTrue. Insert and fetch now round-trip correctly.Out of scope
:json:comment marker (e.g. created by a non-DataJoint tool) will still fail. Adding a heuristic for barelongtextcolumns would be unsound.Test plan
dict, fetch backdict).pytest tests/integration/test_json.pyagainst MySQL — confirm no regression.pytest tests/integration/test_json.pyagainst PostgreSQL — confirm no regression.heading.attributes["metadata"].json is Trueand.type == "longtext"on MariaDB after the insert succeeds.