Skip to content

Commit

Permalink
query field type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadsw committed Dec 18, 2024
1 parent 77b3133 commit 95111dd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
3 changes: 3 additions & 0 deletions specifyweb/express_search/related.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def col_to_fs(col, add_id=False):
display=True,
format_name=None,
sort_type=0,
strict=False
)
for col in Rs.columns
]
Expand All @@ -53,6 +54,7 @@ def col_to_fs(col, add_id=False):
display=True,
format_name=None,
sort_type=0,
strict=False
)
)

Expand All @@ -66,6 +68,7 @@ def make_filter(f, negate):
display=False,
format_name=None,
sort_type=0,
strict=False
)

Rs.filter_fields = [make_filter(f, False) for f in Rs.filters] + [
Expand Down
1 change: 1 addition & 0 deletions specifyweb/stored_queries/batch_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def _query_field(field_spec: QueryFieldSpec, sort_type: int):
display=True,
format_name=None,
sort_type=sort_type,
strict=False
)

def _index(
Expand Down
2 changes: 1 addition & 1 deletion specifyweb/stored_queries/query_construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _predicates_for_node(_node):
# We don't want to include treedef if the rank is not present.
new_filters = [*query.internal_filters, getattr(node, treedef_column).in_(defs_to_filter_on)]
query = query._replace(internal_filters=new_filters)
return query, column
return query, column, current_field_spec.get_field(), table

def tables_in_path(self, table, join_path):
path = deque(join_path)
Expand Down
2 changes: 1 addition & 1 deletion specifyweb/stored_queries/queryfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

EphemeralField = namedtuple(
"EphemeralField",
"stringId isRelFld operStart startValue isNot isDisplay sortType formatName",
"stringId isRelFld operStart startValue isNot isDisplay sortType formatName isStrict",
)


Expand Down
58 changes: 32 additions & 26 deletions specifyweb/stored_queries/queryfieldspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ class TreeRankQuery(Relationship):


class QueryFieldSpec(
namedtuple("QueryFieldSpec", "root_table root_sql_table join_path table date_part")
namedtuple("QueryFieldSpec", "root_table root_sql_table join_path table date_part tree_rank tree_field")
):
root_table: Table
root_sql_table: SQLTable
join_path: FieldSpecJoinPath
table: Table
date_part: Optional[str]
tree_rank: Optional[str]
tree_field: Optional[str]

@classmethod
def from_path(cls, path_in, add_id=False):
Expand Down Expand Up @@ -149,6 +151,8 @@ def from_path(cls, path_in, add_id=False):
date_part=(
"Full Date" if (join_path and join_path[-1].is_temporal()) else None
),
tree_rank=None,
tree_field=None
)

@classmethod
Expand Down Expand Up @@ -177,33 +181,33 @@ def from_stringid(cls, stringid, is_relation):
extracted_fieldname, date_part = extract_date_part(field_name)
field = node.get_field(extracted_fieldname, strict=False)

if field is None: # try finding tree
tree_rank_name, field = find_tree_and_field(node, extracted_fieldname)
if tree_rank_name:
tree_rank = TreeRankQuery(name=tree_rank_name)
# doesn't make sense to query across ranks of trees. no, it doesn't block a theoretical query like family -> continent
tree_rank.relatedModelName = node.name
tree_rank.type = "many-to-one"
join_path.append(tree_rank)
assert field is not None
field = node.get_field(field)

if field is not None:
# if field is None: # try finding tree
# tree_rank_name, field = find_tree_and_field(node, extracted_fieldname)
# if tree_rank_name:
# tree_rank = TreeRankQuery(name=tree_rank_name)
# # doesn't make sense to query across ranks of trees. no, it doesn't block a theoretical query like family -> continent
# tree_rank.relatedModelName = node.name
# tree_rank.type = "many-to-one"
# join_path.append(tree_rank)
# assert field is not None
# field = node.get_field(field)

tree_rank = tree_field = None
if field is None:
# TODO: Check if removing below code breaks #5094
# tree_rank = tree_field = None
# if field is None:
# tree_id_match = TREE_ID_FIELD_RE.match(extracted_fieldname)
# if tree_id_match:
# tree_rank = tree_id_match.group(1)
# tree_field = 'ID'
# else:
# tree_field_match = TAXON_FIELD_RE.match(extracted_fieldname) if node is datamodel.get_table('Taxon') else GEOGRAPHY_FIELD_RE.match(extracted_fieldname) if node is datamodel.get_table('Geography') else None
# if tree_field_match:
# tree_rank = tree_field_match.group(1)
# tree_field = tree_field_match.group(2)
# else:
# tree_rank = extracted_fieldname if extracted_fieldname else None
# else:
tree_id_match = TREE_ID_FIELD_RE.match(extracted_fieldname)
if tree_id_match:
tree_rank = tree_id_match.group(1)
tree_field = 'ID'
else:
tree_field_match = TAXON_FIELD_RE.match(extracted_fieldname) if node is datamodel.get_table('Taxon') else GEOGRAPHY_FIELD_RE.match(extracted_fieldname) if node is datamodel.get_table('Geography') else None
if tree_field_match:
tree_rank = tree_field_match.group(1)
tree_field = tree_field_match.group(2)
else:
tree_rank = extracted_fieldname if extracted_fieldname else None
else:
join_path.append(field)
if field.is_temporal() and date_part is None:
date_part = "Full Date"
Expand All @@ -214,6 +218,8 @@ def from_stringid(cls, stringid, is_relation):
join_path=tuple(join_path),
table=node,
date_part=date_part,
tree_rank=tree_rank,
tree_field=tree_field
)

logger.debug(
Expand Down

0 comments on commit 95111dd

Please sign in to comment.