Skip to content

Conversation

sydney-runkle
Copy link
Contributor

@sydney-runkle sydney-runkle commented Mar 5, 2024

Alternative to #8950.

This breaks the test modified in #7646, though I'm not entirely convinced that's a bad thing. I don't understand the use case where we'd have a dangling ref in an inner schema by the time that we get to the apply_discriminators function call, as we've already called simplify_schema_references within the clean_schema function...

Would love some feedback @adriangb!

Update -- modified the test from #7646 that was failing, as this use case doesn't seem plausible. This changes our discriminated union application logic such that now we:

  • simplify schema references
  • apply discriminators where necessary

Instead of previously, what we were doing:

  • simplify schema references
  • apply discriminators where necessary, with some nasty behavior with refs/defs
  • simplify schema references again, sometimes overwriting the progress we made when applying discriminators 😭

Copy link

cloudflare-workers-and-pages bot commented Mar 5, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0717cb4
Status: ✅  Deploy successful!
Preview URL: https://4f8005f6.pydantic-docs2.pages.dev
Branch Preview URL: https://test-alternative-fix.pydantic-docs2.pages.dev

View logs

@sydney-runkle sydney-runkle changed the title Test alternative fix Remove unnecessary logic for definitions schema gen with discriminated unions Mar 5, 2024
Copy link

codspeed-hq bot commented Mar 5, 2024

CodSpeed Performance Report

Merging #8951 will not alter performance

Comparing test-alternative-fix (0717cb4) with main (a25882c)

Summary

✅ 10 untouched benchmarks

@sydney-runkle sydney-runkle marked this pull request as ready for review March 5, 2024 17:55
@sydney-runkle sydney-runkle added the relnotes-fix Used for bugfixes. label Mar 5, 2024
@sydney-runkle sydney-runkle requested a review from adriangb March 5, 2024 17:56
Comment on lines +38 to +41
# We recursively walk through the `schema` passed to `apply_discriminators`, applying discriminators
# where necessary at each level. During this recursion, we allow references to be resolved from the definitions
# that are originally present on the original, outermost `schema`. Before `apply_discriminators` is called,
# `simplify_schema_references` is called on the schema (in the `clean_schema` function),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just making this a bit more clear

@@ -55,7 +55,7 @@ def inner(s: core_schema.CoreSchema, recurse: _core_utils.Recurse) -> core_schem
s = apply_discriminator(s, discriminator, global_definitions)
return s

return simplify_schema_references(_core_utils.walk_core_schema(schema, inner))
return _core_utils.walk_core_schema(schema, inner)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Woohoo! Performance benefit!

@sydney-runkle sydney-runkle merged commit a99481c into main Mar 5, 2024
@sydney-runkle sydney-runkle deleted the test-alternative-fix branch March 5, 2024 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-fix Used for bugfixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants