From 1f925aa5650a47ca3b269a0ff1542d90714f26b1 Mon Sep 17 00:00:00 2001 From: Tyler Mathis <35553152+tsmathis@users.noreply.github.com> Date: Thu, 23 Oct 2025 15:30:18 -0700 Subject: [PATCH 1/2] add BatchIDQuery to tasks_resource configure batch_id match key in query --- .../emmet/api/routes/materials/materials/query_operators.py | 6 +++++- emmet-api/emmet/api/routes/materials/tasks/resources.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/emmet-api/emmet/api/routes/materials/materials/query_operators.py b/emmet-api/emmet/api/routes/materials/materials/query_operators.py index ded52e97e7..4a8dee51e3 100644 --- a/emmet-api/emmet/api/routes/materials/materials/query_operators.py +++ b/emmet-api/emmet/api/routes/materials/materials/query_operators.py @@ -492,6 +492,10 @@ def query( None, description="Exclude a comma-separated list of batch identifiers", ), + batch_id_field: str = Query( + "builder_meta.batch_id", + description="Field name to query against for batch_id", + ), ) -> STORE_PARAMS: # NOTE: maggma's StringQueryOperator doesn't work for nested fields? all_kwargs = [batch_id, batch_id_not_eq, batch_id_eq_any, batch_id_neq_any] @@ -502,7 +506,7 @@ def query( ) crit = {} # type: dict - k = "builder_meta.batch_id" + k = batch_id_field if batch_id: crit[k] = batch_id elif batch_id_not_eq: diff --git a/emmet-api/emmet/api/routes/materials/tasks/resources.py b/emmet-api/emmet/api/routes/materials/tasks/resources.py index 605103ecdb..0214e6c473 100644 --- a/emmet-api/emmet/api/routes/materials/tasks/resources.py +++ b/emmet-api/emmet/api/routes/materials/tasks/resources.py @@ -2,6 +2,7 @@ from emmet.api.resource import ReadOnlyResource from emmet.api.routes.materials.materials.query_operators import ( + BatchIdQuery, ChemsysQuery, ElementsQuery, FormulaQuery, @@ -26,6 +27,7 @@ def task_resource(task_store): task_store, TaskDoc, query_operators=[ + BatchIdQuery(), FormulaQuery(), ChemsysQuery(), ElementsQuery(), From 5fad69570de92c7c66fb037d72f852cd7a4f7993 Mon Sep 17 00:00:00 2001 From: Tyler Mathis <35553152+tsmathis@users.noreply.github.com> Date: Thu, 23 Oct 2025 15:49:32 -0700 Subject: [PATCH 2/2] add constructor for setting BatchIdQuery target field --- .../api/routes/materials/materials/query_operators.py | 9 ++++----- emmet-api/emmet/api/routes/materials/tasks/resources.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/emmet-api/emmet/api/routes/materials/materials/query_operators.py b/emmet-api/emmet/api/routes/materials/materials/query_operators.py index 4a8dee51e3..e59ca4a764 100644 --- a/emmet-api/emmet/api/routes/materials/materials/query_operators.py +++ b/emmet-api/emmet/api/routes/materials/materials/query_operators.py @@ -474,6 +474,9 @@ def query( class BatchIdQuery(QueryOperator): """Method to generate a query on batch_id""" + def __init__(self, field="builder_meta.batch_id"): + self._field = field + def query( self, batch_id: str | None = Query( @@ -492,10 +495,6 @@ def query( None, description="Exclude a comma-separated list of batch identifiers", ), - batch_id_field: str = Query( - "builder_meta.batch_id", - description="Field name to query against for batch_id", - ), ) -> STORE_PARAMS: # NOTE: maggma's StringQueryOperator doesn't work for nested fields? all_kwargs = [batch_id, batch_id_not_eq, batch_id_eq_any, batch_id_neq_any] @@ -506,7 +505,7 @@ def query( ) crit = {} # type: dict - k = batch_id_field + k = self._field if batch_id: crit[k] = batch_id elif batch_id_not_eq: diff --git a/emmet-api/emmet/api/routes/materials/tasks/resources.py b/emmet-api/emmet/api/routes/materials/tasks/resources.py index 0214e6c473..e9ae152cfe 100644 --- a/emmet-api/emmet/api/routes/materials/tasks/resources.py +++ b/emmet-api/emmet/api/routes/materials/tasks/resources.py @@ -27,7 +27,7 @@ def task_resource(task_store): task_store, TaskDoc, query_operators=[ - BatchIdQuery(), + BatchIdQuery(field="batch_id"), FormulaQuery(), ChemsysQuery(), ElementsQuery(),