Repository navigation
fix(proj): raise for a rename or replicate of a missing attribute - #1681
Conversation
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>
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
Fixes #1677.
proj()checks that every name it mentions is in the heading, but the generator's condition never used the name: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:
Both now raise
DataJointError: Attributenonexistentnot found.. I also changed the quotes in that message to backticks, so it matches theattributescheck just above it.Tests
test_project_missing_source_attributetotests/integration/test_relational_operand.py, for a rename and a replicate.masterboth calls return a heading withoutc, and with the change both raise. A valid rename (proj(c="x")) still works. The internalproj(**attr_map)callers inautopopulate.pyanddiagram.pymap foreign-key attributes that exist in the heading, so they are not affected. CI is the evidence for the full suite.ruff checkpasses on the changed files.