Skip to content

Commit 7aee9aa

Browse files
committed
RDBC-1068 Fix WKT order-by-distance parameterization + DB-facing tests
_order_by_distance_wkt / _order_by_distance_descending_wkt passed the raw WKT string straight in as the parameter *name*, producing spatial.wkt($POINT(...)) which the server rejects at parse time. Register it via add_query_parameter first, matching C# (AbstractDocumentQuery.Spatial). This is the calling-side half of the WKT distance bug (the token-side stray paren was fixed in the previous commit). Adds DB-facing regression tests (embedded server): - spatial: order_by_distance_wkt ascending + descending (fail pre-fix: server 500 parse error). - embeddings: a config with BOTH paths and a transformation is accepted by the server, confirming the dropped client-side mutual-exclusivity rule.
1 parent 03cbf14 commit 7aee9aa

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

ravendb/documents/session/query.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,9 @@ def _order_by_distance_wkt(
15711571

15721572
round_factor_parameter_name = None if round_factor == 0 else self.__add_query_parameter(round_factor)
15731573
self._order_by_tokens.append(
1574-
OrderByToken.create_distance_ascending_wkt(field_name, shape_wkt, round_factor_parameter_name, nulls)
1574+
OrderByToken.create_distance_ascending_wkt(
1575+
field_name, self.__add_query_parameter(shape_wkt), round_factor_parameter_name, nulls
1576+
)
15751577
)
15761578

15771579
def _order_by_distance_descending(
@@ -1627,7 +1629,9 @@ def _order_by_distance_descending_wkt(
16271629
round_factor_parameter_name = None if round_factor == 0 else self.__add_query_parameter(round_factor)
16281630

16291631
self._order_by_tokens.append(
1630-
OrderByToken.create_distance_descending_wkt(field_name, shape_wkt, round_factor_parameter_name, nulls)
1632+
OrderByToken.create_distance_descending_wkt(
1633+
field_name, self.__add_query_parameter(shape_wkt), round_factor_parameter_name, nulls
1634+
)
16311635
)
16321636

16331637
def _init_sync(self) -> None:

ravendb/tests/embeddings_generation_tests/test_tasks_management.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
UpdateEmbeddingsGenerationOperation,
1515
)
1616
from ravendb.documents.operations.ai.embedded_settings import EmbeddedSettings
17+
from ravendb.documents.operations.ai.embeddings_transformation import EmbeddingsTransformation
1718
from ravendb.documents.operations.connection_string.put_connection_string_operation import PutConnectionStringOperation
1819
from ravendb.documents.operations.connection_string.remove_connection_string_operation import (
1920
RemoveConnectionStringOperation,
@@ -214,6 +215,27 @@ def test_embeddings_generation_configuration_without_chunking_options_should_pro
214215
self.assertIn("PostContent", error_message)
215216
self.assertIn("ChunkingOptions", error_message)
216217

218+
def test_can_add_task_with_both_paths_and_transformation(self):
219+
"""The server imposes no mutual-exclusivity between paths and transformation, so a config
220+
that sets BOTH must be accepted (the client must not reject it pre-send either)."""
221+
config = EmbeddingsGenerationConfiguration(
222+
name="ai-task-both",
223+
connection_string_name=self.CONNECTION_STRING_NAME,
224+
embeddings_path_configurations=[
225+
EmbeddingPathConfiguration(path="PostContent", chunking_options=self.DEFAULT_CHUNKING_OPTIONS),
226+
],
227+
embeddings_transformation=EmbeddingsTransformation(
228+
script="embeddings.generate(this.Comments)",
229+
chunking_options=self.DEFAULT_CHUNKING_OPTIONS,
230+
),
231+
collection="Posts",
232+
chunking_options_for_querying=self.DEFAULT_CHUNKING_OPTIONS,
233+
)
234+
235+
add_result = self.store.maintenance.send(AddEmbeddingsGenerationOperation(config))
236+
self.assertIsNotNone(add_result.task_id)
237+
self._created_task_ids.append(add_result.task_id)
238+
217239
def test_database_record_contains_embeddings_generations(self):
218240
config = self._create_valid_config()
219241

ravendb/tests/jvm_migrated_tests/spatial_tests/test_order_by_distance_quoting.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ def test_order_by_distance_descending_with_dynamic_point_field(self):
4848
self.assertGreaterEqual(len(results), 2)
4949
self.assertEqual("geo/2", results[0].Id)
5050

51+
def test_order_by_distance_wkt_ascending_with_dynamic_point_field(self):
52+
# Regression for the create_distance_ascending_wkt RQL bug: a stray ')' produced
53+
# 'spatial.distance(<field>), spatial.wkt(...)', which the server rejects at parse time.
54+
# WKT is "POINT(longitude latitude)"; the point below is geo/1 (Greenwich).
55+
with self.store.open_session() as s:
56+
results = list(
57+
s.query(object_type=_Geo).order_by_distance_wkt(PointField("lat", "lng"), "POINT(0.0015 51.4779)")
58+
)
59+
self.assertGreaterEqual(len(results), 2)
60+
self.assertEqual("geo/1", results[0].Id)
61+
62+
def test_order_by_distance_wkt_descending_with_dynamic_point_field(self):
63+
# Same WKT path, descending: the farthest document (New York) comes first.
64+
with self.store.open_session() as s:
65+
results = list(
66+
s.query(object_type=_Geo).order_by_distance_descending_wkt(
67+
PointField("lat", "lng"), "POINT(0.0015 51.4779)"
68+
)
69+
)
70+
self.assertGreaterEqual(len(results), 2)
71+
self.assertEqual("geo/2", results[0].Id)
72+
5173

5274
if __name__ == "__main__":
5375
unittest.main()

0 commit comments

Comments
 (0)