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
Fix config.defer_build
for serialization first cases
#7024
Conversation
Deploying with Cloudflare Pages
|
just the fastapi tests failing. Please review. |
@MarkusSintonen if you do have a chance to look at this, another cprofile output like you added to #6768 would be really useful 🙏. |
7c71e73
to
51725f5
Compare
@samuelcolvin testing with this branch still gives some strange failures when enabling def test_partial_creation_with_defer_build():
BaseModel.model_config["defer_build"] = True # Actually setup close to the (tests) entrypoint. Feels a bit hacky.
class M(BaseModel):
a: int
b: int
def create_partial(model: type[BaseModel], optionals: set[str]) -> type[BaseModel]:
override_fields: dict[str, tuple[Any, FieldInfo]] = {}
for name, field in model.model_fields.items():
if field.is_required() and name in optionals:
assert field.annotation is not None
override_fields[name] = ((field.annotation | None), FieldInfo.merge_field_infos(field, default=None))
return create_model(f"Partial{model.__name__}", __base__=model, **cast(dict, override_fields))
partial = create_partial(M, {"a"})
# Comment this away and the last assertion works
assert M.model_json_schema()["required"] == ["a", "b"]
# AssertionError: assert ['a', 'b'] == ['b']
assert partial.model_json_schema()["required"] == ["b"] |
With
2.1.1 without
|
This is really useful, thank you.
Hoped, but not expected. 🤷 We have some big plans in the works to remove some calls to walk, in the meantime we'll continue to look for smaller improvements. |
Needs to be refreshed |
bce37cf
to
9e0f4f2
Compare
Thanks so much @MarkusSintonen I've added your tests to our unit tests, unfortunately since In summary, you'll need to call |
e7dd2da
to
c1f947e
Compare
please review. |
c1f947e
to
1977786
Compare
Change Summary
@MarkusSintonen might be a good idea if you try this as a PR, rather than waiting a release to find my dumb bugs 🙃 ?
Related issue number
continues from #6823 as per comment from @MarkusSintonen #6768 (comment)
Checklist
Selected Reviewer: @dmontagu