-
Notifications
You must be signed in to change notification settings - Fork 20
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/jobs/search not robust enough with DateTime? #341
Comments
How about class ScalarSearchSpec(TypedDict):
parameter: str
operator: ScalarSearchOperator
- value: str | int
+ value: str | int | datetime |
Aha, this is caused by insufficient escaping: https://stackoverflow.com/questions/16531116/python-valueerror-unsupported-format-character-y-0x59 Probably needs to be fixed here: diracx/diracx-db/src/diracx/db/sql/utils/__init__.py Lines 93 to 116 in 1a4dc95
Probably need to ensure double-escaped |
This works: @compiles(date_trunc, "postgresql")
def pg_date_trunc(element, compiler, **kw):
res = {
"SECOND": "second",
"MINUTE": "minute",
"HOUR": "hour",
"DAY": "day",
"MONTH": "month",
"YEAR": "year",
}[element._time_resolution]
return f"date_trunc('{res}', {compiler.process(element.clauses)})"
@compiles(date_trunc, "mysql")
def mysql_date_trunc(element, compiler, **kw):
pattern = {
"SECOND": "%Y-%m-%d %H:%i:%S",
"MINUTE": "%Y-%m-%d %H:%i",
"HOUR": "%Y-%m-%d %H",
"DAY": "%Y-%m-%d",
"MONTH": "%Y-%m",
"YEAR": "%Y",
}[element._time_resolution]
dt_col, = list(element.clauses)
return compiler.process(
func.date_format(
dt_col, pattern
)
)
@compiles(date_trunc, "sqlite")
def sqlite_date_trunc(element, compiler, **kw):
pattern = {
"SECOND": "%Y-%m-%d %H:%M:%S",
"MINUTE": "%Y-%m-%d %H:%M",
"HOUR": "%Y-%m-%d %H",
"DAY": "%Y-%m-%d",
"MONTH": "%Y-%m",
"YEAR": "%Y",
}[element._time_resolution]
dt_col, = list(element.clauses)
return compiler.process(
func.strftime(
pattern, dt_col,
)
) |
Great! Thanks 🙂 But there are 2 different issues here:
Have you added some tests for your change? IIUC, we would need to add unit tests working with Note for myself: I found this package for freezing dates and prevent potential flaky unit tests dealing with date times: https://github.com/spulec/freezegun |
Looks like
diracX
is not able to process submission time format coming fromdiracX-web
:Not sure yet whether it's the fault of
diracX
ordiracX-web
, but it sounds likediracX
is not robust enough:The text was updated successfully, but these errors were encountered: