Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API fix: with_query_tag()/without_query_tag() #555

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}*")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just a warning? The server should ideally just silently ignore them

Copy link
Member Author

@fantix fantix Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same, but we will send e.g. gel/repl tags from the CLI or gel/ui from the UI/JS client, while the server has no knowledge about the peer identity; the server could also receive myapp/financial-queries equally, so it just records the tags as received without ignoring. Unless you meant to reserve gel/* for only server-internal queries like in some table GC tasks (instead of queries over the binary protocol), adding an error in client bindings is the last chance we can enforce exclusiveness on this tag namespace.

if len(tag) > 128:
raise errors.InvalidArgumentError(
"tag too long (> 128 characters)"
)
Comment on lines +421 to +424
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we check this server-side also?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we do!


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
Loading