Skip to content

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
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.

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!

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
@azmeuk azmeuk deleted the issue-17659-check-pydantic-models branch September 11, 2024 21:13
azmeuk added a commit to yaal-coop/synapse that referenced this pull request Nov 13, 2024
This ensures the compatibility with scim2-models.

The replaces HAS_PYDANTIC_V2 by PYDANTIC_VERSION, but HAS_PYDANTIC_V2
was not used anymore since element-hq#17667
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