docs: document Top(order_by="_name") in hidden-attribute matrix#163
Open
dimitri-yatsenko wants to merge 1 commit intomainfrom
Open
docs: document Top(order_by="_name") in hidden-attribute matrix#163dimitri-yatsenko wants to merge 1 commit intomainfrom
dimitri-yatsenko wants to merge 1 commit intomainfrom
Conversation
Top.order_by is not validated against heading.names — it flows from condition.py:142-148 (type check only) through expression.py:241-254 (restrict() short-circuits on Top before the heading.names check) into _flatten_attribute_list / _wrap_attributes, which quote the name and concatenate it into ORDER BY. So a hidden column shapes the result order even though its value never returns to Python. This is the same shape as string restrictions: DataJoint-generated SQL references the hidden column, but the visible-only filter on the SELECT list keeps its value out of the result set. Worth one row in the behavior matrix so users querying "5 most recently populated rows" via Top(5, order_by="_job_start_time DESC") see it as an explicitly supported pattern rather than an undocumented bypass.
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
Adds one row to the §3.4 hidden-attribute behavior matrix to document that
dj.Top(order_by="_name")flows through to SQLORDER BYwithout heading validation.Why this row is missing today
The current matrix (added in #162) covers reads (
fetch/proj/to_dicts/...), writes (insert/update1), restrictions (dict and string), joins,describe(), and indexes — but notTop. Worth a row becauseTop.order_bybehaves like the string-restriction case (passes the column name through to SQL untouched), so a hidden column can legitimately shape the result order even though its value can never return to Python.Code path
Top.__post_init__(condition.py:142-148) — type-checksorder_byis a string or list of strings; no name validation.restrict()(expression.py:241-254) — when the restriction is aTop, short-circuits withreturn resultat line 254, before reaching theheading.namescheck at lines 260-262 that fires for non-Top conditions.sorting_clauses()(expression.py:133-145) →_flatten_attribute_list(:1580-1604, only special-cases"KEY") →_wrap_attributes(:1607-1617, regex\b((?!asc|desc)\w+)\bquotes the name as`_name`).ORDER BY. TheSELECTlist is still built fromheading.namesatexpression.py:163, so the value never returns to Python.Worked example
Generated SQL (visible columns only in
SELECT; hidden column referenced only inORDER BY):Caveat
Because
Topdoes no name check, a typoed column name passes DataJoint validation and fails as a SQL error from the DB. Not a hidden-attribute concern specifically, but worth knowing the failure mode if you mistype_job_start_tine.Test plan
python scripts/gen_llms_full.pyregenerates cleanly.