Skip to content

fix: return empty string for empty filter list in parse_metadata_filters_recursive - #415

Open
evanerwee wants to merge 1 commit into
awslabs:mainfrom
evanerwee:fix/408-empty-filter-where-clause
Open

fix: return empty string for empty filter list in parse_metadata_filters_recursive#415
evanerwee wants to merge 1 commit into
awslabs:mainfrom
evanerwee:fix/408-empty-filter-where-clause

Conversation

@evanerwee

Copy link
Copy Markdown
Contributor

Summary

When MetadataFilters has an empty filters list, parse_metadata_filters_recursive returns "()" (from joining an empty list within parentheses). This truthy string bypasses the guard in VersionManager._get_existing_source_nodes() at line 70:

if not where_clauses:  # "()" is truthy — guard fails
    return []

This causes the VersionManager to generate invalid Cypher:

WHERE () AND coalesce(source.__aws__versioning__id_fields__, ...) = $param

Neptune Database (1.4.7.0) rejects this with:

MalformedQueryException: Invalid input 'A': expected whitespace, comment or a relationship pattern

Fix

Return '' (empty string) when filter_strs is empty, before reaching the condition-based join logic.

if not filter_strs:
    return ''

Testing

  • Added 2 unit tests covering empty filter lists with AND and OR conditions
  • Verified on Neptune Database 1.4.7.0: the versioning query now works correctly
  • Confirmed via direct Neptune query testing that Neptune supports all other Cypher features used by the VersionManager (map literals, coalesce, __ property names)

Evidence

Direct Neptune testing results (from issue #408):

Test Query Pattern Result
Map literal in RETURN RETURN {id: id(n)} AS result ✅ Works
__aws__ property names t.__aws__versioning__id_fields__ ✅ Works
coalesce on versioning properties coalesce(t.__aws__versioning__valid_from__, -1) ✅ Works
WHERE () AND filter WHERE () AND id(n) IS NOT NULL ❌ MalformedQueryException
Full versioning query (properly formed) Complete pattern with valid WHERE ✅ Works

Fixes #408

…ers_recursive

When MetadataFilters has an empty filters list, the function previously
returned '()' (from joining an empty list within parentheses). This truthy
string bypassed the guard in VersionManager._get_existing_source_nodes(),
causing invalid Cypher: WHERE () AND <filter>

Neptune Database rejects this with MalformedQueryException:
  Invalid input 'A': expected whitespace, comment or a relationship pattern

Fix: return '' (empty string) when filter_strs is empty, before reaching
the condition-based join logic.

Fixes awslabs#408

@mykola-pereyma mykola-pereyma left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Thank you!

@oussamahansal

Copy link
Copy Markdown
Collaborator

@evanerwee Can you please resolve the conflict and rebase before we merge it. Thank you!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: VersionManager generates invalid Cypher WHERE () AND ... on Neptune Database

3 participants