-
Notifications
You must be signed in to change notification settings - Fork 7
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
frozenset[str] fields in API get shuffled #1348
Comments
This should be about as easy as replacing the def freezeStrings(strings: Iterable[str]) -> tuple[str]:
deduped = {s: None for s in strings}
return tuple(s for s in deduped) |
Probably the right move is this change to _converters.py, so that fields can still be made immutable and hashable, but without losing ordering (or having duplicates removed). This change might just work on its own, but there's a bunch of cleanup to do, mostly switching type hints. Also this would touch the auth component, which makes me want to tread carefully. diff --git a/src/ims/model/_convert.py b/src/ims/model/_convert.py
index 14b817ca..500c78fe 100644
--- a/src/ims/model/_convert.py
+++ b/src/ims/model/_convert.py
@@ -20,19 +20,19 @@
Converters
"""
-from collections.abc import Iterable
+from collections.abc import Iterable, Sequence
from datetime import datetime as DateTime
__all__ = ()
-def freezeIntegers(integers: Iterable[int]) -> frozenset[int]:
- return frozenset(integers)
+def freezeIntegers(integers: Iterable[int]) -> Sequence[int]:
+ return tuple(i for i in integers)
-def freezeStrings(strings: Iterable[str]) -> frozenset[str]:
- return frozenset(strings)
+def freezeStrings(strings: Iterable[str]) -> Sequence[str]:
+ return tuple(s for s in strings) |
These currently show up in the order they're returned from the API, which is effectively random, due to this issue: #1348 We might as well do client-side sorting even if we also do something on the server-side too.
These currently show up in the order they're returned from the API, which is effectively random, due to this issue: #1348 We might as well do client-side sorting even if we also do something on the server-side too.
It's kind of unfortunate that we end up shuffling collections in API fields. For example, I noticed this in the ranger_handles field in the incidents endpoint (like this one: https://ranger-ims-staging.burningman.org/ims/api/events/2023/incidents/), and it's presumably the same for incident_types (https://ranger-ims-staging.burningman.org/ims/api/incident_types/).
Even if you start with sorted values in _db.py, they eventually get shuffled before encoding, because frozenset[str] are unordered, e.g. below
FYI @wsanchez
The text was updated successfully, but these errors were encountered: