Skip to content
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

fix: request type annotation None is now correctly supported and value-check and supports "null" #1429

Merged
merged 2 commits into from
Feb 27, 2025

Conversation

sveneberth
Copy link
Member

@sveneberth sveneberth commented Feb 26, 2025

Resolves #1423

  • "null" is helpful if you build requests in JS have null values
  • If a annotation is missing, it's param.empty but this is difference to an explicit set None type annotation and needs to processed separately as empty
  • The other "simple types" do a type-cast and would raise a ValueError in case of invalid data, but None was always taken, regardless of the value?!

Here some examples of definition which had some issues before and are now working as expected:

    @exposed
    def my_method(
        self,
        *,
        test0: None | db.Key | str = None,
        test1: None = None,
        test2: None | str = None,
        test3: str | None = None,
        test4=None,
        test5: int = None,
    ):

Of course test1: None = None is a little bit impractical, but since it's a valid syntax it should also work in this way and accept only None, "None" or "null". But test4 has no type annotation and accepts any value as-is.

Providing "None" for test2 would result into None, while "None" for test3 would result into "None" (due to the order).

However, my initially problem parameter test0: None | db.Key | str = None, is now working as expected: I can provide explicit "None" or "null" and it's no longer always None.

@sveneberth sveneberth added bug(fix) Something isn't working or address a specific issue or vulnerability Priority: High After critical issues are fixed, these should be dealt with before any further issues. labels Feb 26, 2025
@sveneberth sveneberth added this to the ViUR-core v3.7 milestone Feb 26, 2025
@sveneberth sveneberth changed the title fix: None is now correclty supported and value-check and support "null" fix: None is now correctly supported and value-check and supports "null" Feb 26, 2025
@sveneberth sveneberth changed the title fix: None is now correctly supported and value-check and supports "null" fix: request type annotation None is now correctly supported and value-check and supports "null" Feb 26, 2025
@phorward phorward force-pushed the fix/None_type_annotation branch from 731f082 to db7951d Compare February 26, 2025 13:47
@phorward phorward self-requested a review February 26, 2025 18:55
@phorward phorward force-pushed the fix/None_type_annotation branch from db7951d to 54aaef0 Compare February 27, 2025 07:57
@phorward phorward merged commit f1aaf8b into viur-framework:main Feb 27, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug(fix) Something isn't working or address a specific issue or vulnerability Priority: High After critical issues are fixed, these should be dealt with before any further issues.
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

type cast "None" to None in request parameters
3 participants