-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
add opt-in strict string format #451
base: main
Are you sure you want to change the base?
Conversation
92dee76
to
a69a432
Compare
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.
let me know:
-
if you know a good place to go grab some representative data for these
-
if I should add tests elsewhere covering generated interfaces
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.
no need for generated interfaces. but it will be good to have smth like this:
class TestModel(ModelBase):
did_field: str_frmt.DidField...
def test_did_field_validation:
test_data = {did_field: blaablabla}
with pytestExpectException(ValueError) as exc_info:
get_or_create(test_data, TestModel, string_strings=True)
assert 'did invalid` in str(exc_info)
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.
speaking of test data i will try to find it later somewhere in official bsky repo
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.
@zzstoatzz hi pls use this files for tests https://github.com/bluesky-social/atproto/tree/main/interop-test-files/syntax. Just download it from the official repo and put to this one. pls do not rename of modify these files. because we want to keep it with easy sync with the official repo without additional effort
47c3aab
to
571edfa
Compare
def only_validate_if_strict(validate_fn: core_schema.WithInfoValidatorFunction) -> Callable: | ||
"""Skip validation if not opting into strict validation.""" | ||
|
||
def wrapper(v: str, info: ValidationInfo) -> str: | ||
if not (info and isinstance(info.context, Mapping) and info.context.get(_OPT_IN_KEY, False)): | ||
return v | ||
return validate_fn(v, info) | ||
|
||
return wrapper |
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.
here's the critical "pydantic usage" making use of validation context
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.
could we try to invert this if statement? to avoid using of "not"
smth like:
def only_validate_if_strict(validate_fn: core_schema.WithInfoValidatorFunction) -> Callable: | |
"""Skip validation if not opting into strict validation.""" | |
def wrapper(v: str, info: ValidationInfo) -> str: | |
if not (info and isinstance(info.context, Mapping) and info.context.get(_OPT_IN_KEY, False)): | |
return v | |
return validate_fn(v, info) | |
return wrapper | |
def only_validate_if_strict(validate_fn: core_schema.WithInfoValidatorFunction) -> Callable: | |
"""Skip validation if not opting into strict validation.""" | |
def wrapper(v: str, info: ValidationInfo) -> str: | |
if info and isinstance(info.context, Mapping) and info.context.get(_OPT_IN_KEY, False): | |
return validate_fn(v, info) | |
return v | |
return wrapper |
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.
awesome hard work! thank you! speaking of your gotten knowledges about how to contribute we need to write CONTRIBUTING.md
someday. but this will be separated PR for sure
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.
no need for generated interfaces. but it will be good to have smth like this:
class TestModel(ModelBase):
did_field: str_frmt.DidField...
def test_did_field_validation:
test_data = {did_field: blaablabla}
with pytestExpectException(ValueError) as exc_info:
get_or_create(test_data, TestModel, string_strings=True)
assert 'did invalid` in str(exc_info)
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.
speaking of test data i will try to find it later somewhere in official bsky repo
remove example file update codegen run the things add tests
6ad722a
to
6de9cac
Compare
adds pydantic validation per #406 (comment). see the usage example
does not address open questions regarding the language types or
re2
. happy to chat on those if they'd be blocking heremay close #406
notes
I ran this to generate models
and this to update docs
and this to run the new tests
if desirable, I can follow up this PR to add contribution instructions to the current README section (for
uv
at least, and perhaps a TODO for properpoetry
usage, since I don't really use that) - let me know!