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

Add better error message for improper definition of RootModel with Generic #8804

Closed

Conversation

Massakera
Copy link

Change Summary

This PR add a new error message when creating a generic RootModel without providing the generic to the model in the class inheritance. Now, it mention the needed parametrization of the RootModel itself

Related issue number

fix #8712

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@Massakera
Copy link
Author

somehow I'm having these errors and I don't know how to proceed

/pydantic/pydantic/_internal/_model_construction.py
/pydantic/pydantic/_internal/_model_construction.py:188:21 - error: Cannot assign member "__pydantic_generic_metadata__" for type "type[RootModel[Unknown]]"
    Expression of type "dict[str, Unknown]" cannot be assigned to member "__pydantic_generic_metadata__" of class "RootModel[Unknown]"
      Member "__set__" is unknown
      "dict[str, Unknown]" is incompatible with "PydanticGenericMetadata" (reportGeneralTypeIssues)
/pydantic/pydantic/_internal/_model_construction.py:188:21 - error: Cannot assign member "__pydantic_generic_metadata__" for type "type[BaseModel]"
    Expression of type "dict[str, Unknown]" cannot be assigned to member "__pydantic_generic_metadata__" of class "BaseModel"
      Member "__set__" is unknown
      "dict[str, Unknown]" is incompatible with "PydanticGenericMetadata" (reportGeneralTypeIssues)
2 errors, 0 warnings, 0 informations

@Massakera Massakera marked this pull request as draft February 13, 2024 17:57
@Massakera Massakera changed the title [Draft] adding error-message for RootModel adding error-message for RootModel Feb 13, 2024
Copy link
Member

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

A few notes:

  1. There was a lot of reformatting done that I don't think is necessary - you can probably revert these changes with make format, and fix the linting errors as well. That should make the diff a lot smaller
  2. Please add a test to showcase the new behavior
  3. You'll want to dedent the call to raise TypeError(error_message) to make sure that it's raised in any of the 3 cases being handled

@sydney-runkle sydney-runkle added the relnotes-change Used for changes to existing functionality which don't have a better categorization. label Feb 13, 2024
@sydney-runkle sydney-runkle changed the title adding error-message for RootModel Add better error message for improper definition of RootModel with Generic Feb 13, 2024
@sydney-runkle
Copy link
Member

Closing in favor of #8857. Thanks for the good start on this work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting author revision relnotes-change Used for changes to existing functionality which don't have a better categorization.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Weird error message on creating a generic RootModel
2 participants