Skip to content

Commit

Permalink
API fix: with_query_tag()/without_query_tag()
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Dec 3, 2024
1 parent 7d50d0b commit c3fdce8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions gel/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


_RetryRule = namedtuple("_RetryRule", ["attempts", "backoff"])
TAG_NAME = "tag"


def default_backoff(attempt):
Expand Down Expand Up @@ -413,17 +414,25 @@ def without_globals(self, *global_names):
)
return result

def with_annotation(self, name: str, value: str):
def with_query_tag(self, tag: str):
for prefix in ["edgedb/", "gel/"]:
if tag.startswith(prefix):
raise errors.InvalidArgumentError(f"reserved tag: {prefix}*")
if len(tag) > 128:
raise errors.InvalidArgumentError(
"tag too long (> 128 characters)"
)

result = self._shallow_clone()
result._options = self._options.with_annotations(
self._options.annotations | {name: value}
self._options.annotations | {TAG_NAME: tag}
)
return result

def without_annotation(self, name: str):
def without_query_tag(self):
result = self._shallow_clone()
annotations = self._options.annotations.copy()
annotations.pop(name, None)
annotations.pop(TAG_NAME, None)
result._options = self._options.with_annotations(annotations)
return result

Expand Down

0 comments on commit c3fdce8

Please sign in to comment.