Repository navigation
Conversation
Several error paths in the query evaluator crashed with Python errors: - `b = a.x.y`: the error message had one `%` argument for two `%s` (TypeError). It now names the expression. - `for x in 3:` left `list_items` unbound (UnboundLocalError). Iterating over anything but a list of names or a string pattern now raises. - `import f` with a syntax error in `f` used Python 2 `exc_value[1][1]` (TypeError) and named an `ast.alias` object as the file. It now reports the file name, line and text from the SyntaxError. - `medial_of(a)` / `lateral_of(a)` without `.left`/`.right` left `side` unbound, and `anterior_of(a.foo)` left `query_info` unbound. The argument is now validated, before the empty-atlas shortcut so that `queries_syntax_check` also reports it. - A relative term over a query with no labels leaked `StopIteration`; it now raises TractQuerierLabelNotFound. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 4, 2026
This branch has not been deployed
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.
What was wrong
Each row of the table in #103 reproduces on master. I ran
queries_preprocess+eval_queriesagainst a small spatial index with non-empty label bounding boxes. Two of the rows cannot be reached throughqueries_syntax_check, because it uses an empty atlas.a = 1/b = a.x.yTypeError: not enough arguments for format stringTractQuerierSyntaxError: Invalid query in line 2: a.x.ya = 1/for x in 3:/b = xUnboundLocalError: list_itemsTractQuerierSyntaxError: Error in FOR statement in line 2, it must iterate over a list of query names or a string patternimport f.qrywheref.qryhas a syntax errorTypeError: 'SyntaxError' object is not subscriptableTractQuerierSyntaxError: syntax error in file <path>/f.qry line N: <line>a = 1/b = medial_of(a)(alsolateral_of)UnboundLocalError: sideTractQuerierSyntaxError: medial_of needs a query ending in .left or .right. Line 2a = 1 - 1/b = anterior_of(a)(empty label set; also an unmatched'pattern*')StopIterationTractQuerierLabelNotFound: anterior_of applied to a query with no labels. Line 2I found one more crash in the same branch of
process_relative_term, not listed in the issue:a.foo = 1/b = anterior_of(a.foo)gaveUnboundLocalError: query_info. It now raises the existingAttribute not recognized for relative specificationerror.Change
All changes are in
tract_querier/query_processor.py:visit_Attribute: give the format string both of its arguments. The message showsast.unparse(node).visit_For: add anelse: raisefor iterables that are neither a list nor a string.RewritePreprocess.visit_Import: build the message from theSyntaxError(filename,lineno,text). Before, it used Python 2 tuple indexing, andmodule_namewas anast.alias.process_relative_term:sidenow starts asNone, and onlyNameor.left/.rightarguments are accepted.medial_of/lateral_ofwithout a side raise an error. This validation now runs before the empty-atlasreturn FiberQueryInfo(), soqueries_syntax_check(which the CLI runs before loading data) also catches these errors. An empty label set raisesTractQuerierLabelNotFound.Behaviour change / maintainer decision: a relative term over a query with an empty label set now raises
TractQuerierLabelNotFoundinstead ofStopIteration. The alternative is to return an empty result, as the function already does when the atlas has no labels at all. None of the packaged.qryfiles can produce an empty label set: their relative-term arguments are all label-defined*.sidequeries. So raising does not affect them. If you prefer the empty result, it is a one-line change.Valid queries return the same results as before.
Testing
tract_querier/tests/test_query_errors.py, with a parametrised test of every row above plus thea.foocase, checking the exception class and message. It also includes aqueries_syntax_checktest for the rows reachable there, and a positivemedial_of/anterior_oftest. On master'squery_processor.py, 11 of these 12 tests fail. The positive test passes on both.python -m pytest -q -p no:cacheprovider tract_querier: 54 passed, 1 skipped. This includestest_query_files, which checks the syntax of every packaged query file.Merge order: independent of #130 (#38), which touches
queries_preprocessa few lines belowvisit_Import. The two may conflict textually. They use the same newsyntax error in file ... line ...wording. #139 (#115, Python 2 leftovers) touchesvisit_Callin the same file, but in different lines.Closes #103
🤖 Generated with Claude Code