Skip to content

Commit dfc86f1

Browse files
committed
Document edge case and() on improper use
1 parent a430b42 commit dfc86f1

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

terminusdb_client/tests/test_woql_subquery_aggregation.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,55 @@ def test_aggregation_with_distinct(self):
317317
assert result is query
318318
assert query._query.get("@type") == "Count"
319319

320-
320+
# @pytest.mark.skip(reason="""BLOCKED: Lines 852-853 in woql_query.py - edge case not covered
321+
322+
# PROBLEM: Lines 852-853 handle initialization of the "and" array when woql_and()
323+
# is called on a query that already has @type="And" but no "and" key yet.
324+
325+
# This is an edge case that occurs when:
326+
# 1. A query's cursor is manually set to {"@type": "And"} without an "and" array
327+
# 2. Then woql_and() is called to add queries
328+
329+
# The code checks: if "and" not in self._cursor:
330+
# Then initializes: self._cursor["and"] = []
331+
332+
# This edge case is difficult to trigger through normal API usage because:
333+
# - woql_and() always sets both @type and initializes the "and" array
334+
# - The only way to get @type="And" without "and" is through manual manipulation
335+
336+
# RECOMMENDATION: This is defensive programming for an edge case that shouldn't
337+
# occur in normal usage. Consider either:
338+
# 1. Remove this check if it's truly unreachable through the public API
339+
# 2. Add internal validation to prevent this state
340+
# 3. Document this as defensive code and accept the uncovered lines
341+
# """)
342+
def test_woql_and_with_uninitialized_and_array(self):
343+
"""Test woql_and() when cursor has @type='And' but no 'and' array.
344+
345+
This tests lines 852-853 which defensively initialize the "and" array
346+
if it doesn't exist. This edge case occurs when the cursor is manually
347+
manipulated to have @type="And" without the corresponding "and" array.
348+
349+
This is a TDD test showing the CORRECT expected behavior for this edge case.
350+
"""
351+
query = WOQLQuery()
352+
353+
# Manually create the edge case: @type="And" but no "and" array
354+
# This simulates corrupted state or manual cursor manipulation
355+
query._cursor["@type"] = "And"
356+
# Deliberately NOT setting query._cursor["and"] = []
357+
358+
# Now call woql_and() with a query - should initialize "and" array
359+
q1 = WOQLQuery().triple("v:X", "rdf:type", "schema:Person")
360+
result = query.woql_and(q1)
361+
362+
# Should have initialized the "and" array and added the query
363+
assert result is query
364+
assert query._cursor["@type"] == "And"
365+
assert "and" in query._cursor
366+
assert isinstance(query._cursor["and"], list)
367+
assert len(query._cursor["and"]) == 1
368+
assert query._cursor["and"][0]["@type"] == "Triple"
321369

322370
class TestWOQLSubqueryAggregationIntegration:
323371
"""Test integration of subqueries with aggregation."""

0 commit comments

Comments
 (0)