Workflow Object ID Filtering
Developer guide for the Enezaframework workflow engine. Part of the Workflow series.
Table of Contents
- Overview
SavedQuery.get_queryset(object_id=None)- object_id Type
- Methods That Accept object_id
- Non-Workflow Callers
- Related Guides
Overview
Object ID filtering restricts a saved query's results to a single record. It exists because condition steps were previously evaluated against the whole table: when the same logical data appeared across documents, a condition could match a record from a different document and produce a false positive. Passing the document's primary key scopes the query to the record being evaluated.
The behavior is additive — when object_id is None, no filtering is applied.
flowchart LR
Q["SavedQuery"] --> A["annotations + rules"]
A --> B["filtered queryset"]
B --> C{"object_id provided?"}
C -->|Yes| D["filter(pk=object_id)"]
C -->|No| E["return as-is"]SavedQuery.get_queryset(object_id=None)
Defined in enezaworkflowengine/models/querybuilder.py:31-60:
def get_queryset(self, object_id=None):
model_class = self.content_type.model_class()
if not model_class:
raise ValueError("Model not found")
annotations = self.filters_json.get('annotations', []) if isinstance(self.filters_json, dict) else []
if annotations:
ann = parse_annotations(model_class, annotations)
qs = model_class.objects.annotate(**ann)
else:
qs = model_class.objects.all()
# ... build Q from rules or groups ...
result_qs = qs.filter(q)
if object_id is not None:
result_qs = result_qs.filter(pk=object_id)
return result_qs
The object filter is applied after the rule filter, so it narrows the already-matching set.
object_id Type
object_id is a string. Framework models use UUID primary keys, and Django's ORM accepts a UUID string directly in pk=..., so no manual coercion is needed. The workflow engine converts the document PK with str(document.pk) before passing it (enezaworkflowengine/services/condition_step.py:36).
Methods That Accept object_id
| Method | Signature | Notes |
|---|---|---|
SavedQuery.get_queryset() |
get_queryset(object_id=None) |
Primary implementation. |
SavedQuery.execute() |
execute(object_id=None) |
Alias — forwards to get_queryset(). |
SavedQuery.execute_new_format() |
execute_new_format(object_id=None) |
Groups-format parser; also applies annotations and object_id. |
All three apply the same if object_id is not None: .filter(pk=object_id) guard.
Non-Workflow Callers
Callers outside the workflow engine — reports, the admin query builder, tests — can omit object_id; it defaults to None and no filtering occurs.
# All matching records
results = saved_query.get_queryset()
# Only the record with that primary key
results = saved_query.get_queryset(object_id="550e8400-e29b-41d4-a716-446655440000")
This is the backward-compatible behavior the enhancement preserves.