Skip to content

Fix jobs table generation for uuid FK-derived primary keys (#1515)#1518

Merged
dimitri-yatsenko merged 1 commit into
masterfrom
fix/jobs-uuid-fk-pk
Jul 21, 2026
Merged

Fix jobs table generation for uuid FK-derived primary keys (#1515)#1518
dimitri-yatsenko merged 1 commit into
masterfrom
fix/jobs-uuid-fk-pk

Conversation

@dimitri-yatsenko

Copy link
Copy Markdown
Member

Fixes #1515.

Problem

Accessing .jobs on a Computed/Imported table whose primary key is FK-derived from a uuid attribute crashed with:

DataJointError: Unsupported attribute type binary(16)

This fires on the first .jobs access for such a table — including the implicit access inside populate(reserve_jobs=True) — and never recovers, since the ~~jobs table stays undeclared. It disables reserve_jobs=True entirely for the common, recommended pattern of using uuid root keys with downstream computed tables.

Root cause

Job._generate_definition() builds the ~~jobs table's DataJoint definition string from the target's FK-derived primary key. For each attribute it emitted attr.type — the backend-resolved SQL type (binary(16) for a uuid) — rather than the DataJoint-level alias the user wrote (uuid). binary(16) is not valid DataJoint definition syntax, so when Job.declare() re-parsed the generated string, match_type("binary(16)") matched no pattern and raised.

Fix

Use attr.original_type or attr.type in _get_fk_derived_pk_attrs, mirroring the fallback DataJoint already uses in heading.py (original_type = attr["original_type"] or attr["type"]). original_type holds the DataJoint alias for core types (uuid, float32, …) and is None otherwise, so:

  • uuid PK → definition line item : uuid (re-parses correctly; DataJoint resolves it back to binary(16) internally).
  • any other core-type alias in an FK-derived PK is fixed the same way, not just uuid.
  • non-alias types are unaffected (fall back to attr.type as before).

Test

Adds test_jobs_table_uuid_fk_derived_pk (plus a BasicComputed table in the uuid test schema: a Computed table whose PK is FK-derived from a uuid parent). It asserts the generated definition carries uuid (not binary(16)), that .jobs.refresh() declares the table, and that the PK attribute round-trips to original_type == "uuid".

Job._generate_definition() emitted attr.type (the backend-resolved SQL type,
e.g. binary(16) for a uuid attribute) into a fresh DataJoint definition
string. That resolved type is not valid DataJoint definition syntax, so
declaring the ~~jobs table raised 'Unsupported attribute type binary(16)'
on the first .jobs access (including inside populate(reserve_jobs=True)),
and never recovered.

Use attr.original_type (the DataJoint-level alias, e.g. uuid) with a
fallback to attr.type, mirroring the fallback DataJoint already uses in
heading.py. This makes jobs-table generation correct for every core-type
alias in an FK-derived primary key (uuid, float32, ...), not just uuid.

Adds a regression test: a Computed table whose primary key is FK-derived
from a uuid attribute.

@MilagrosMarin MilagrosMarin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

Small strengthening: the fix mirrors the same original_type or type fallback in TWO existing sites — heading.py:543 AND table.py:1327 (inside Table.describe). Worth mentioning the second precedent in the PR body — reinforces "jobs.py was the outlier missing the pattern" rather than "one-off similarity".

Optional hardening: test uses uuid only, but the fix generalizes to any core-type alias. A parameterized second case (e.g., decimal(6,3) PK) would catch a hypothetical mis-regression like if original_type == "uuid": ... else: attr.type. Non-blocking — the fix generalizes by construction (the or short-circuit applies to any attribute whose original_type is set).

@dimitri-yatsenko dimitri-yatsenko modified the milestones: v2.3.2, v2.3.3 Jul 21, 2026
@dimitri-yatsenko
dimitri-yatsenko merged commit d9ce6b7 into master Jul 21, 2026
13 checks passed
@dimitri-yatsenko
dimitri-yatsenko deleted the fix/jobs-uuid-fk-pk branch July 21, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Indicates an unexpected problem or unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Auto-generated jobs table crashes when a Computed/Imported table's primary key derives from a uuid attribute

2 participants