Skip to content

Conversation

sydney-runkle
Copy link
Contributor

Contributing to #10314

from pydantic import BaseModel
from pydantic.v1 import BaseModel as BaseModelV1

class V1Model(BaseModelV1):
    ...

class V2Model(BaseModel):
    inner: V1Model

"""
UserWarning: Nesting V1 models inside V2 models is not supported. Please upgrade V1Model to V2.
"""

@sydney-runkle sydney-runkle changed the title Adding v1 / v2 incompatibility warning for nested v1 model: Adding v1 / v2 incompatibility warning for nested v1 model Sep 17, 2024
@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Sep 17, 2024
@sydney-runkle sydney-runkle added relnotes-feature and removed relnotes-fix Used for bugfixes. labels Sep 17, 2024
Copy link

cloudflare-workers-and-pages bot commented Sep 17, 2024

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8f9599f
Status: ✅  Deploy successful!
Preview URL: https://3c809738.pydantic-docs.pages.dev
Branch Preview URL: https://incompat-warning.pydantic-docs.pages.dev

View logs

Copy link

codspeed-hq bot commented Sep 17, 2024

CodSpeed Performance Report

Merging #10431 will not alter performance

Comparing incompat-warning (8f9599f) with main (59a3de7)

Summary

✅ 49 untouched benchmarks

Copy link
Contributor

github-actions bot commented Sep 17, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic/_internal
  _dataclasses.py
  _model_construction.py
Project Total  

This report was generated by python-coverage-comment-action

Comment on lines 826 to 830
if issubclass(obj, BaseModelV1):
warn(
f'Nesting V1 models inside V2 models is not supported. Please upgrade `{obj.__name__}` to V2.',
UserWarning,
)
Copy link
Member

Choose a reason for hiding this comment

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

This will warn when doing the following:

from pydantic import TypeAdapter
from pydantic.v1 import BaseModel as BaseModelV1

TypeAdapter(BaseModelV1)

So maybe there's a way to check for the current model stack before warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, we don't support TypeAdapter with v1 models anyways... so maybe I should just make the warning more broad?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've modified the warning accordingly

@sydney-runkle sydney-runkle enabled auto-merge (squash) September 18, 2024 13:57
@sydney-runkle sydney-runkle merged commit fbfcc60 into main Sep 18, 2024
59 checks passed
@sydney-runkle sydney-runkle deleted the incompat-warning branch September 18, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants