Skip to content

Commit 9019c7d

Browse files
authored
API fix: with_query_tag()/without_query_tag() (#555)
1 parent 5e779d3 commit 9019c7d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

gel/options.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414

1515
_RetryRule = namedtuple("_RetryRule", ["attempts", "backoff"])
16+
TAG_NAME = "tag"
1617

1718

1819
def default_backoff(attempt):
@@ -414,17 +415,25 @@ def without_globals(self, *global_names):
414415
)
415416
return result
416417

417-
def with_annotation(self, name: str, value: str):
418+
def with_query_tag(self, tag: str):
419+
for prefix in ["edgedb/", "gel/"]:
420+
if tag.startswith(prefix):
421+
raise errors.InvalidArgumentError(f"reserved tag: {prefix}*")
422+
if len(tag) > 128:
423+
raise errors.InvalidArgumentError(
424+
"tag too long (> 128 characters)"
425+
)
426+
418427
result = self._shallow_clone()
419428
result._options = self._options.with_annotations(
420-
self._options.annotations | {name: value}
429+
self._options.annotations | {TAG_NAME: tag}
421430
)
422431
return result
423432

424-
def without_annotation(self, name: str):
433+
def without_query_tag(self):
425434
result = self._shallow_clone()
426435
annotations = self._options.annotations.copy()
427-
annotations.pop(name, None)
436+
annotations.pop(TAG_NAME, None)
428437
result._options = self._options.with_annotations(annotations)
429438
return result
430439

0 commit comments

Comments
 (0)