Skip to content

Restriction follow-ups: a uuid restricted by bytes raises TypeError; MySQL JSON object values with non-ASCII text never match #1715

Open

Description

@dimitri-yatsenko

Summary

Follow-ups to the restriction-value changes in 2.3.6 (GHSA-pv3r-mxv6-wccj).

Bugs

  • Restricting a uuid attribute by a bytes value raises TypeError. prep_value in condition.py calls uuid.UUID(v) and catches only AttributeError and ValueError. With bytes, uuid.UUID raises TypeError, which escapes as a bare Python error. Raise the usual DataJointError ("Badly formed UUID ..."), or accept 16-byte values as uuid.UUID(bytes=v).
  • On MySQL, a JSON object value with non-ASCII text never matches. A dict value for a JSON path is rendered with json.dumps(v), which escapes non-ASCII characters (ensure_ascii=True). The stored JSON holds the characters themselves, so a restriction such as {"data.sub": {"name": "Zoë"}} matches no rows. Render the value with ensure_ascii=False, or compare through CAST(... AS JSON).

Tests

Restriction values are covered for plain tables. Add tests for:

  • restrictions on a join, on a renamed proj, on an aggr, and with dj.Top;
  • a cascading delete() and update1() with such restrictions;
  • values taken from record arrays, np.void rows, and DataFrame rows.

Activity

  1. added this to the v2.3.7 milestone on Nov 20, 2026
  2. added
    bugIndicates an unexpected problem or unintended behavior
    on Nov 20, 2026
  3. dimitri-yatsenko commented on Nov 21, 2026

    @dimitri-yatsenko
    MemberAuthor

    Reproduced against MySQL 8.0 and PostgreSQL 15 on current master:

    • {"data.sub": {"name": "Zoë"}} matches no rows on MySQL, as described. It also matches no rows on PostgreSQL. Both servers render the stored object as {"name": "Zoë"}, while json.dumps sends {"name": "Zo\u00eb"}.
    • Table & {"token": some_uuid.bytes} raises TypeError on both backends. Inserting bytes into a uuid attribute raises the same TypeError.

    Both are fixed in #1735, together with the tests listed above.

    Three related findings that the PR does not change:

    1. A dict value is still compared as text, so key order matters. With a stored object {"a": 2, "b": 1}, the restriction {"data.sub": {"a": 2, "b": 1}} matches but {"data.sub": {"b": 1, "a": 2}} does not, on both backends. Both servers print object keys in their own normalized order. Comparing dict values as JSON values would remove this. That would build on the JSON value comparison proposed in fix(json): make JSON path annotations and value comparisons portable #1607, so it is left for a decision once that lands.
    2. On PostgreSQL, a uuid attribute does not work end to end on current master. Inserting a uuid.UUID fails with column ... is of type uuid but expression is of type bytea. Restricting by a uuid.UUID fails with operator does not exist: uuid = bit. Fetching a row inserted with plain SQL fails with bytes is not a 16-char string. The integration test for bytes values therefore checks only the error on PostgreSQL, not matching rows.
    3. Restricting an aggregation by an attribute and then fetching a subset of attributes that leaves that attribute out generates invalid SQL. For example, (Item.aggr(Tag, "name", n="count(*)") & {"name": "b"}).to_arrays("item_id") fails with Unknown column 'name' in 'having clause' on MySQL and column "name" does not exist on PostgreSQL. to_dicts() works. This looks like the restriction counterpart of keys() and to_arrays(attr) fail on an aggregation with dj.Top ordered by an aggregate #1670. The new tests fetch whole rows for that case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions