fix: ORDER BY on aliased RETURN DISTINCT property no longer raises#494
Conversation
) - Remove `not item.alias` guard in projected_prop_paths collection so aliased PropertyAccess items (e.g. `a.year AS year`) are tracked - Add two unit tests and two integration tests for the alias case Closes #481
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdjusted RETURN DISTINCT validation so projected property paths include PropertyAccess expressions even when the RETURN item has an alias; tests added to cover valid and invalid ORDER BY usages with aliased properties. ChangesRETURN DISTINCT + ORDER BY Validation Fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #494 +/- ##
==========================================
- Coverage 88.01% 88.01% -0.01%
==========================================
Files 40 40
Lines 14449 14449
Branches 3430 3430
==========================================
- Hits 12718 12717 -1
Misses 1141 1141
- Partials 590 591 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/integration/test_distinct_clause.py (1)
146-178: ⚡ Quick winParametrize the ASC/DESC aliased-property ORDER BY integration cases.
These two tests exercise the same behavior with different inputs/directions;
@pytest.mark.parametrizewould reduce duplication and make expansions easier.♻️ Suggested refactor shape
class TestReturnDistinctOrderByAliasedProperty: - def test_order_by_aliased_property_works(self): - ... - def test_order_by_aliased_property_desc(self): - ... + `@pytest.mark.parametrize`( + ("create_query", "run_query", "key", "expected"), + [ + ( + """ + CREATE (:Item {name: 'C', year: 2023}), + (:Item {name: 'A', year: 2021}), + (:Item {name: 'A', year: 2021}), + (:Item {name: 'B', year: 2022}) + """, + """ + MATCH (a:Item) + RETURN DISTINCT a.year AS year + ORDER BY a.year ASC + """, + "year", + [2021, 2022, 2023], + ), + ( + """ + CREATE (:Person {name: 'Alice'}), + (:Person {name: 'Bob'}), + (:Person {name: 'Alice'}) + """, + """ + MATCH (p:Person) + RETURN DISTINCT p.name AS name + ORDER BY p.name DESC + """, + "name", + ["Bob", "Alice"], + ), + ], + ) + def test_order_by_aliased_property(self, create_query, run_query, key, expected): + gf = GraphForge() + gf.execute(create_query) + results = gf.execute(run_query) + assert [r[key].value for r in results] == expectedAs per coding guidelines,
tests/**/*.py: "Use pytest parametrization (@pytest.mark.parametrize) when testing the same logic with different inputs to avoid code duplication".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/integration/test_distinct_clause.py` around lines 146 - 178, Replace the two nearly identical tests test_order_by_aliased_property_works and test_order_by_aliased_property_desc with a single parametrized test using pytest.mark.parametrize that iterates over ORDER BY directions (e.g., "ASC" and "DESC") and expected outputs; inside the new test (keep using GraphForge and gf.execute to create the same fixtures), build the query string with the direction parameter, execute it, and assert the result length and the ordered values (for years or names) match the expected list per parameter set; reference the existing test names (test_order_by_aliased_property_works, test_order_by_aliased_property_desc) and the RETURN DISTINCT ... AS usage when locating where to consolidate and assert.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/integration/test_distinct_clause.py`:
- Around line 146-178: Replace the two nearly identical tests
test_order_by_aliased_property_works and test_order_by_aliased_property_desc
with a single parametrized test using pytest.mark.parametrize that iterates over
ORDER BY directions (e.g., "ASC" and "DESC") and expected outputs; inside the
new test (keep using GraphForge and gf.execute to create the same fixtures),
build the query string with the direction parameter, execute it, and assert the
result length and the ordered values (for years or names) match the expected
list per parameter set; reference the existing test names
(test_order_by_aliased_property_works, test_order_by_aliased_property_desc) and
the RETURN DISTINCT ... AS usage when locating where to consolidate and assert.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3e5e49e8-4b63-42bf-b35a-e7fe5c6a8b3e
📒 Files selected for processing (3)
src/graphforge/planner/planner.pytests/integration/test_distinct_clause.pytests/unit/planner/test_syntax_error_validation.py
* docs: analytics guide, installation extras, KG/agent doc fixes (#457 #456 #455 #454 #453 #473 #503) - Add docs/guide/analytics-integration.md covering to_dicts/to_dataframe/ to_networkx/to_igraph/to_json/from_json with choosing-between table - Update docs/getting-started/installation.md with all optional extras (pandas, networkx, igraph, analytics, zstandard) and bump to v0.3.10 - Update examples/05_migration_from_networkx.py with working to_networkx() replacing the "future feature" placeholder - Update docs/use-cases/knowledge-graph-construction.md: add add_graph_documents() section, CREATE vs MERGE idempotency warning, fix shortestPath to raise NotImplementedError with BFS workaround - Update research docs to mark resolved: FP-1/FP-5/FP-6 in llm-workflows and network-analysis, FP-2/FP-4/FP-5/FP-6 in kg-construction, Engine Bug 1/2 in agent-grounding (PRs #494 #495); update pass/fail matrix for S4 and S10 (20 PASS / 5 PARTIAL / 4 FAIL) Closes #457, #456, #455, #454, #453, #473, #503 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: zero-base rebuild of docs publishing pipeline (#506) - Move docs deps from optional-dependencies to [dependency-groups] - Rewrite CI workflow: uv sync --group docs (lock-file reproducible), caching, src/** trigger - Remove dead version.provider: mike from mkdocs.yml - Add docs-serve, docs-build, docs-clean Makefile targets - Pin pygments<2.20 in docs group (2.20.0 breaks pymdownx title=None handling) - Drop pygments>=2.20.0 constraint (Lua ReDoS CVE not relevant to graphforge) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…456 #455 #454 #453 #473 #503) (#505) - Add docs/guide/analytics-integration.md covering to_dicts/to_dataframe/ to_networkx/to_igraph/to_json/from_json with choosing-between table - Update docs/getting-started/installation.md with all optional extras (pandas, networkx, igraph, analytics, zstandard) and bump to v0.3.10 - Update examples/05_migration_from_networkx.py with working to_networkx() replacing the "future feature" placeholder - Update docs/use-cases/knowledge-graph-construction.md: add add_graph_documents() section, CREATE vs MERGE idempotency warning, fix shortestPath to raise NotImplementedError with BFS workaround - Update research docs to mark resolved: FP-1/FP-5/FP-6 in llm-workflows and network-analysis, FP-2/FP-4/FP-5/FP-6 in kg-construction, Engine Bug 1/2 in agent-grounding (PRs #494 #495); update pass/fail matrix for S4 and S10 (20 PASS / 5 PARTIAL / 4 FAIL) Closes #457, #456, #455, #454, #453, #473, #503 Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Closes #481
Summary
RETURN DISTINCT a.year AS year ORDER BY a.yearraisedUndefinedVariablebecause the planner'sprojected_prop_pathsset excluded aliasedPropertyAccessitems (guarded bynot item.alias)PropertyAccessin RETURN DISTINCT is tracked, aliased or notORDER BY a.ageon a completely unprojected property still raises correctlyTest plan
test_distinct_return_aliased_property_allows_same_path_in_order_by— was failing, now passestest_distinct_return_aliased_property_disallows_other_path_in_order_by— still raises for truly unprojected propertytest_order_by_aliased_property_works— integration: dedup + correct sort ordertest_order_by_aliased_property_desc— DESC variantTestReturnDistinctOrderBytests still passmake pre-pushgreen (87.07% total coverage)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmithwith what you need.Summary by CodeRabbit
Bug Fixes
Tests