Skip to content

Commit 84d94c3

Browse files
committed
Align wtih new idgen_random predicate
1 parent 44e663b commit 84d94c3

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

terminusdb_client/tests/test_woqlQuery.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from .woqljson.woqlConcatJson import WOQL_CONCAT_JSON
1616
from .woqljson.woqlIdgenJson import (
1717
WOQL_IDGEN_JSON,
18-
WOQL_RANDOM_IDGEN_JSON,
18+
WOQL_RANDOM_KEY_JSON,
1919
WOQL_UNIQUE_JSON,
2020
)
2121
from .woqljson.woqlJoinSplitJson import WOQL_JOIN_SPLIT_JSON
@@ -214,11 +214,9 @@ def test_idgen_method(self):
214214
woql_object = WOQLQuery().idgen("Station", "v:Start_ID", "v:Start_Station_URL")
215215
assert woql_object.to_dict() == WOQL_IDGEN_JSON
216216

217-
def test_random_idgen_method(self):
218-
woql_object = WOQLQuery().random_idgen(
219-
"Station", "v:Start_ID", "v:Start_Station_URL"
220-
)
221-
assert woql_object.to_dict() == WOQL_RANDOM_IDGEN_JSON
217+
def test_idgen_random_method(self):
218+
woql_object = WOQLQuery().idgen_random("Person/", "v:Person_ID")
219+
assert woql_object.to_dict() == WOQL_RANDOM_KEY_JSON
222220

223221
def test_typecast_method(self):
224222
woql_object = WOQLQuery().typecast(

terminusdb_client/tests/woqljson/woqlIdgenJson.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,14 @@
2727
},
2828
}
2929

30-
WOQL_RANDOM_IDGEN_JSON = {
30+
WOQL_RANDOM_KEY_JSON = {
3131
"@type": "RandomKey",
3232
"base": {
3333
"@type": "DataValue",
34-
"data": {"@type": "xsd:string", "@value": "Station"},
35-
},
36-
"key_list": {
37-
"@type": "DataValue",
38-
"variable": "Start_ID",
34+
"data": {"@type": "xsd:string", "@value": "Person/"},
3935
},
4036
"uri": {
4137
"@type": "NodeValue",
42-
"variable": "Start_Station_URL",
38+
"variable": "Person_ID",
4339
},
4440
}

terminusdb_client/woqlquery/woql_query.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,35 +2207,36 @@ def idgen(self, prefix, input_var_list, output_var):
22072207
self._cursor["uri"] = self._clean_node_value(output_var)
22082208
return self
22092209

2210-
def random_idgen(self, prefix, key_list, uri):
2211-
"""Randomly generates an ID and appends to the end of the key_list.
2210+
def idgen_random(self, prefix, uri):
2211+
"""Generates a unique ID with cryptographically secure random suffix.
2212+
2213+
Uses base64 encoding to generate 16-character random IDs that are
2214+
guaranteed to be unique across executions. Matches the server's
2215+
idgen_random/2 predicate and maintains consistency with the JavaScript client.
22122216
22132217
Parameters
22142218
----------
22152219
prefix : str
2216-
prefix for the id
2217-
key_list : str
2218-
variable to generate id for
2220+
A prefix for the IDs to be generated (e.g. "Person/")
22192221
uri : str
2220-
the variable to hold the id
2222+
Variable name or output target for the generated ID
22212223
22222224
Returns
22232225
-------
22242226
WOQLQuery object
2225-
query object that can be chained and/or execute
2227+
query object that can be chained and/or executed
22262228
22272229
Examples
22282230
-------
2229-
>>> WOQLQuery().random_idgen("https://base.url",["page","1"],"v:obj_id").execute(client)
2230-
{'@type': 'api:WoqlResponse', 'api:status': 'api:success', 'api:variable_names': ['obj_id'], 'bindings': [{'obj_id': 'http://base.url_page_1_rv1mfa59ekisdutnxx6zdt2fkockgah'}], 'deletes': 0, 'inserts': 0, 'transaction_retry_count': 0}
2231+
>>> WOQLQuery().idgen_random("Person/", "v:person_id").execute(client)
2232+
{'@type': 'api:WoqlResponse', 'api:status': 'api:success', 'api:variable_names': ['person_id'], 'bindings': [{'person_id': 'Person/aB3dEf9GhI2jK4lM'}], 'deletes': 0, 'inserts': 0, 'transaction_retry_count': 0}
22312233
"""
22322234
if prefix and prefix == "args":
2233-
return ["base", "key_list", "uri"]
2235+
return ["base", "uri"]
22342236
if self._cursor.get("@type"):
22352237
self._wrap_cursor_with_and()
22362238
self._cursor["@type"] = "RandomKey"
22372239
self._cursor["base"] = self._clean_data_value(prefix)
2238-
self._cursor["key_list"] = self._data_list(key_list)
22392240
self._cursor["uri"] = self._clean_node_value(uri)
22402241
return self
22412242

0 commit comments

Comments
 (0)