Skip to content

Commit

Permalink
fix known_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariana Barzinpour committed Oct 23, 2024
1 parent 85ab5c2 commit 0650c4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
7 changes: 3 additions & 4 deletions datacube/drivers/postgis/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,13 +661,12 @@ def search_datasets_query(self,
if not select_fields:
select_fields = _dataset_fields()

known_fields = set().union(get_native_fields().values(), select_fields)
known_fields = get_native_fields() | {f.name: f.alchemy_expression for f in select_fields}

def _ob_exprs(o):
if isinstance(o, str):
for f in known_fields:
if o.lower() == f.name:
return f.alchemy_expression
if known_fields.get(o.lower()):
return known_fields[o.lower()]
raise ValueError(f"Cannot order by unknown field {o}")
elif isinstance(o, PgField):
return o.alchemy_expression
Expand Down
23 changes: 10 additions & 13 deletions datacube/drivers/postgres/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ def _dataset_uri_field(table):


def _base_known_fields():
return (
*get_native_fields().values(),
NativeField(
"uris",
"all active uris",
_ALL_ACTIVE_URIS,
)
fields = get_native_fields().copy()
fields["uris"] = NativeField(
"uris",
"all active uris",
_ALL_ACTIVE_URIS,
)
return fields


def get_native_fields() -> dict[str, NativeField]:
Expand Down Expand Up @@ -555,17 +554,15 @@ def search_datasets_query(expressions, source_exprs=None,
f.alchemy_expression.label(f.name) if f is not None else None
for f in select_fields
)
known_fields = _base_known_fields() | {f.name: f.alchemy_expression for f in select_fields}
else:
select_fields = []
select_columns = _DATASET_SELECT_FIELDS

known_fields = set().union(_base_known_fields(), select_fields)
known_fields = _base_known_fields()

def _ob_exprs(o):
if isinstance(o, str):
for f in known_fields:
if o.lower() == f.name:
return f.alchemy_expression
if known_fields.get(o.lower()):
return known_fields[o.lower()]
raise ValueError(f"Cannot order by unknown field {o}")
elif isinstance(o, PgField):
return o.alchemy_expression
Expand Down

0 comments on commit 0650c4c

Please sign in to comment.