Skip to content

fix(proj): raise for a rename or replicate of a missing attribute - #1681

Merged
dimitri-yatsenko merged 1 commit into
datajoint:masterfrom
mayuriphad:fix/1677-proj-missing-source
Nov 19, 2026
Merged

dimitri-yatsenko merged 1 commit into
datajoint:masterfrom
mayuriphad:fix/1677-proj-missing-source

Conversation

@mayuriphad

Copy link
Copy Markdown
Contributor

Fixes #1677.

proj() checks that every name it mentions is in the heading, but the generator's condition never used the name:

next(a for a in mentions if not self.heading.names)

A heading always has names, so the generator was empty and the check passed. A rename or replicate of a missing attribute was dropped without an error, and the result had no column with the new name:

A().proj(c="nonexistent")    # before: heading ['id_a'], no error
A().proj(c="(nonexistent)")  # before: same

Both now raise DataJointError: Attribute nonexistent not found.. I also changed the quotes in that message to backticks, so it matches the attributes check just above it.

Tests

  • Added test_project_missing_source_attribute to tests/integration/test_relational_operand.py, for a rename and a replicate.
  • I don't have MySQL or PostgreSQL here, so I couldn't run the integration suite locally. I checked the fix against a heading built in memory: on master both calls return a heading without c, and with the change both raise. A valid rename (proj(c="x")) still works. The internal proj(**attr_map) callers in autopopulate.py and diagram.py map foreign-key attributes that exist in the heading, so they are not affected. CI is the evidence for the full suite.
  • ruff check passes on the changed files.
The check for mentioned names used `if not self.heading.names`, which
never refers to the attribute and is always false, so a rename or
replicate of an attribute missing from the heading was silently dropped.

Fixes datajoint#1677

Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 14, 2026 04:56

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@dimitri-yatsenko dimitri-yatsenko added this to the v2.3.7 milestone Nov 18, 2026

@dimitri-yatsenko dimitri-yatsenko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. The cause is as described: the condition never tested a, so the check could not fire.

I ran the full suite on this branch merged with current master, on MySQL and PostgreSQL: 2041 passed, 17 skipped, including both new cases. The internal callers that pass renames to proj are the cascade in diagram.py, _rename_attributes in autopopulate.py, and dj.U.aggr. They all rename attributes that exist, so nothing relied on the rename being dropped.

Optional: the issue's fourth example, PA.aggr(PB, n="count(*)").proj(xx="x"), goes through the same check. One more case in the test would cover a projection of an aggregation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants