-
Notifications
You must be signed in to change notification settings - Fork 30
Allow limits on user settings, with per-group overrides #9594
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
8cfd995
84c81a7
6c053c3
3049e9f
afeb0bb
4f98673
4df09af
64766a0
c363a2a
9e8cd3a
7edcaa1
5815dbf
c179a38
53a801e
14a3bbe
caf6b8e
c8fdce1
0b2c976
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,33 @@ | ||
| from typing import Any, TypeAlias | ||
| from typing import Annotated, Any | ||
|
|
||
| from pydantic import BaseModel, Field | ||
|
|
||
| from ..user_preferences import PreferenceIdentifier | ||
| from ._base import InputSchema, OutputSchema | ||
|
|
||
|
|
||
| class PreferenceConstraints(OutputSchema): | ||
| """Limits applying to a preference value, used by the frontend to render its widget.""" | ||
|
|
||
| ge: int | float | None = None | ||
| gt: int | float | None = None | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reminded me so much pydantci's internal code. SEE https://github.com/pydantic/pydantic/blob/main/pydantic/fields.py#L67-L71 IMO it is worth exploring the possibility of using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Short answer, current approach is better. Long answer. You could use annotated_types, which do bring a better way to express the "constraints", at least in python. I think this version is more compact and simple to maintain, for our limited purposes here. |
||
| le: int | float | None = None | ||
| lt: int | float | None = None | ||
| max_length: int | None = None | ||
| min_length: int | None = None | ||
| multiple_of: int | float | None = None | ||
| pattern: str | None = None | ||
|
|
||
|
|
||
| class Preference(OutputSchema): | ||
| default_value: Any = Field(default=..., description="used by the frontend") | ||
| value: Any = Field(default=..., description="preference value") | ||
| default_value: Annotated[Any, Field(description="used by the frontend")] | ||
| value: Annotated[Any, Field(description="preference value")] | ||
| constraints: Annotated[PreferenceConstraints | None, Field(description="null when the value is unconstrained")] = ( | ||
|
GitHK marked this conversation as resolved.
|
||
| None | ||
| ) | ||
|
|
||
|
|
||
| AggregatedPreferences: TypeAlias = dict[PreferenceIdentifier, Preference] | ||
| type AggregatedPreferences = dict[PreferenceIdentifier, Preference] | ||
|
|
||
|
|
||
| class PatchRequestBody(InputSchema): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do you handle conflicting constraints? e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same way Pydantic does, by doing nothing. This would be a configuration issue and will break.