diff --git a/.gitignore b/.gitignore index ac51e6e..85a4b9b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ docker-compose.y*ml .coverage *.egg-info +.idea/ dist build docs/_build diff --git a/CHANGELOG.md b/CHANGELOG.md index 18b1a29..61a1e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention. +## [0.8.13] - 11/15/2024 + +### Fixed + +- Handle attribute value passed as epoch time in `_filter_to_restriction` + ## [0.8.12] - 2024-10-03 ### Fixed diff --git a/pharus/interface.py b/pharus/interface.py index b291859..cf8f0d6 100644 --- a/pharus/interface.py +++ b/pharus/interface.py @@ -518,9 +518,16 @@ def _filter_to_restriction(attribute_filter: dict, attribute_type: str) -> str: else: operation = attribute_filter["operation"] + if ( + re.match(r"^datetime.*$", attribute_type) + or re.match(r"timestamp", attribute_type) + ) and str(attribute_filter["value"]).isnumeric(): + attribute_filter["value"] = f"FROM_UNIXTIME({attribute_filter['value']})" + if ( isinstance(attribute_filter["value"], str) and not attribute_filter["value"].isnumeric() + and not attribute_filter["value"].startswith("FROM_UNIXTIME") ): value = ( f"X'{attribute_filter['value'].replace('-', '')}'" diff --git a/pharus/server.py b/pharus/server.py index 5fe9c85..f1823d5 100644 --- a/pharus/server.py +++ b/pharus/server.py @@ -164,7 +164,7 @@ def api_version() -> str: Content-Type: application/json { - "version": "0.8.12" + "version": "0.8.13" } ``` diff --git a/pharus/version.py b/pharus/version.py index ed981cb..e1e1d7b 100644 --- a/pharus/version.py +++ b/pharus/version.py @@ -1,3 +1,3 @@ """Package metadata.""" -__version__ = "0.8.12" +__version__ = "0.8.13" diff --git a/setup.py b/setup.py index a53c1ea..8ac53b9 100644 --- a/setup.py +++ b/setup.py @@ -14,11 +14,13 @@ with open(path.join(here, "requirements.txt")) as f: requirements = [ - "{pkg} @ {target}#egg={pkg}".format( - pkg=re.search(r"/([A-Za-z0-9\-]+)\.git", r).group(1), target=r + ( + "{pkg} @ {target}#egg={pkg}".format( + pkg=re.search(r"/([A-Za-z0-9\-]+)\.git", r).group(1), target=r + ) + if "+" in r + else r ) - if "+" in r - else r for r in f.read().splitlines() if "#" not in r ] diff --git a/tests/__init__.py b/tests/__init__.py index cb2cb77..0561fa5 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -374,6 +374,10 @@ class Student(dj.Lookup): for i in range(100) ] + Student.insert1( + (110, "Unix Time", "123-45-6789", "2022-05-06 12:11:10", 2000.0, None, 0) + ) + yield Student Student.drop() diff --git a/tests/test_filter.py b/tests/test_filter.py index 7a375d5..4f761bd 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -62,6 +62,21 @@ def test_filters(token, client, Student): assert REST_records[0][6] == 0 +def test_filters_from_unixtime(token, client, Student): + # unix time 1651839070: "2022-05-06 12:11:10" + restriction = [ + dict(attributeName="student_enroll_date", operation="=", value=1651839070), + ] + encoded_restriction = b64encode(dumps(restriction).encode("utf-8")).decode("utf-8") + q = dict(limit=10, page=1, order="student_id ASC", restriction=encoded_restriction) + REST_records = client.get( + f'/schema/{Student.database}/table/{"Student"}/record?{urlencode(q)}', + headers=dict(Authorization=f"Bearer {token}"), + ).json["records"] + assert len(REST_records) == 1 + assert REST_records[0][1] == "Unix Time" + + def test_uuid_filter(token, client, Computer): """Verify UUID can be properly restricted.""" restriction = [