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

Fix UUID handling in OData queries #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 7 additions & 6 deletions odata_query/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
_INTEGER = r"[+-]?\d+"
_DATE = r"[1-9]\d{3}-(?:0\d|1[0-2])-(?:[0-2]\d|3[01])"
_TIME = r"(?:[01]\d|2[0-3]):[0-5]\d(:?:[0-5]\d(?:\.\d{1,12})?)"
_UUID_PATTERN = r"'?[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}'?"

# Defines known functions and min/max nr of args:
ODATA_FUNCTIONS = {
Expand Down Expand Up @@ -132,6 +133,12 @@ def DURATION(self, t):
t.value = ast.Duration(val)
return t

@_(_UUID_PATTERN)
def GUID(self, t):
":meta private:"
t.value = ast.GUID(t.value.strip("'"))
return t

@_(r"'(?:[^']|'')*'")
def STRING(self, t):
":meta private:"
Expand All @@ -153,12 +160,6 @@ def GEOGRAPHY(self, t):
t.value = ast.Geography(t.value[10:-1])
return t

@_(r"[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}")
def GUID(self, t):
":meta private:"
t.value = ast.GUID(t.value)
return t

@_(_DATE + r"T" + _TIME + r"?(Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)?")
def DATETIME(self, t):
":meta private:"
Expand Down
4 changes: 2 additions & 2 deletions odata_query/sqlalchemy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
or_,
true,
)
from sqlalchemy.types import Date, Time
from sqlalchemy.types import Date, Time, Uuid

from odata_query import ast, exceptions as ex, typing, visitor

Expand Down Expand Up @@ -81,7 +81,7 @@ def visit_Duration(self, node: ast.Duration) -> BindParameter:

def visit_GUID(self, node: ast.GUID) -> BindParameter:
":meta private:"
return literal(node.val)
return literal(node.py_val, type_=Uuid())

def visit_List(self, node: ast.List) -> list:
":meta private:"
Expand Down
Loading