Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions store/backend/neurostore/tests/api/test_base_studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,29 @@ def test_feature_display_and_pipeline_config(auth_client, ingest_demographic_fea
assert len(mismatch_response.json()["results"]) == 0


def test_pipeline_config_with_quoted_value(
auth_client, ingest_demographic_features
):
"""Ensure quoted config filter values do not break jsonpath parsing."""
quoted_resp = auth_client.get(
"/api/base-studies/?"
'pipeline_config=ParticipantDemographicsExtractor:1.0.0:'
'extractor_kwargs.extraction_model="gpt-4-turbo"'
)
assert quoted_resp.status_code == 200

unquoted_resp = auth_client.get(
"/api/base-studies/?"
"pipeline_config=ParticipantDemographicsExtractor:1.0.0:"
"extractor_kwargs.extraction_model=gpt-4-turbo"
)
assert unquoted_resp.status_code == 200

quoted_ids = {result["id"] for result in quoted_resp.json()["results"]}
unquoted_ids = {result["id"] for result in unquoted_resp.json()["results"]}
assert quoted_ids == unquoted_ids


def test_feature_flatten(auth_client, ingest_demographic_features):
"""Test flattening nested feature objects into dot notation"""
# Get response without flattening
Expand Down
15 changes: 13 additions & 2 deletions store/backend/neurostore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,19 @@ def build_jsonpath(field_path: str, operator: str, value: str) -> str:
Returns:
PostgreSQL jsonpath query string
"""
def normalize_value(raw_val: str):
# Strip surrounding quotes so users can include quoted values without
# creating invalid jsonpath strings.
if (
len(raw_val) >= 2
and raw_val[0] == raw_val[-1]
and raw_val[0] in {"'", '"'}
):
raw_val = raw_val[1:-1]
return determine_value_type(raw_val)

# Handle regular field queries
cast_val, is_numeric = determine_value_type(value)
cast_val, is_numeric = normalize_value(value)

# Map operators
op_map = {"~": "like_regex", "=": "==", ">": ">", "<": "<", ">=": ">=", "<=": "<="}
Expand All @@ -51,7 +62,7 @@ def build_jsonpath(field_path: str, operator: str, value: str) -> str:
values = []
for val in value.split("|"):
val = val.strip()
cast_val, is_numeric = determine_value_type(val)
cast_val, is_numeric = normalize_value(val)
if isinstance(cast_val, bool):
values.append(str(cast_val).lower())
elif is_numeric:
Expand Down
Loading