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

import pydantic objects from the _pydantic_compat module #17667

Merged

Conversation

azmeuk
Copy link
Contributor

@azmeuk azmeuk commented Sep 5, 2024

This PR changes from pydantic import BaseModel to from synapse._pydantic_compat import BaseModel (as well as constr, conbytes, conint, confloat).

It allows check_pydantic_models.py to mock those pydantic objects only in the synapse module, and not interfere with pydantic objects in external dependencies.

This should solve the CI problems for #17144, which breaks because check_pydantic_models.py patches pydantic models from scim2-models.

/cc @DMRobertson @gotmax23
fixes #17659

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct
    (run the linters)

this allows `check_pydantic_models.py` to mock those pydantic objects
only in the synapse module, and not interfere with pydantic objects in
external dependencies
@azmeuk azmeuk requested a review from a team as a code owner September 5, 2024 11:01
@@ -384,7 +380,7 @@ class TypingExtension(RequestBodyModel):
receipts: Optional[ReceiptsExtension] = None
typing: Optional[TypingExtension] = None

conn_id: Optional[str]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My modifications revealed an issue with this str type that was rejected by check_pydantic_models. I am not sure if this was wanted though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems fine to me. conn_id should be a string.

synapse/config/_util.py Outdated Show resolved Hide resolved
Copy link
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new ergonomics of the imports are great. Thanks for this!

@@ -384,7 +380,7 @@ class TypingExtension(RequestBodyModel):
receipts: Optional[ReceiptsExtension] = None
typing: Optional[TypingExtension] = None

conn_id: Optional[str]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems fine to me. conn_id should be a string.

@devonh devonh merged commit ebad618 into element-hq:develop Sep 11, 2024
39 checks passed
@azmeuk azmeuk deleted the issue-17659-check-pydantic-models branch September 11, 2024 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

check_pydantic_models.py should ignore external modules
4 participants