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

✅ Try reproducing rebuilding recursive schema with a ForwardRef #6159

Merged
merged 1 commit into from Jun 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/test_forward_ref.py
Expand Up @@ -957,3 +957,37 @@ class Foobar(BaseModel):
a: UndefinedType

Foobar(a=1)


def test_rebuild_recursive_schema():
from typing import ForwardRef, List

class Expressions_(BaseModel):
model_config = dict(undefined_types_warning=False)
items: List["types['Expression']"]

class Expression_(BaseModel):
model_config = dict(undefined_types_warning=False)
Or: ForwardRef("types['allOfExpressions']")
Not: ForwardRef("types['allOfExpression']")

class allOfExpression_(BaseModel):
model_config = dict(undefined_types_warning=False)
Not: ForwardRef("types['Expression']")

class allOfExpressions_(BaseModel):
model_config = dict(undefined_types_warning=False)
items: List["types['Expression']"]

types_namespace = {
'types': {
'Expression': Expression_,
'Expressions': Expressions_,
'allOfExpression': allOfExpression_,
'allOfExpressions': allOfExpressions_,
}
}

models = [allOfExpressions_, Expressions_]
for m in models:
m.model_rebuild(_types_namespace=types_namespace)