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

quartodoc is not compatible w/ pydantic v2 #209

Closed
schloerke opened this issue Jun 30, 2023 · 7 comments
Closed

quartodoc is not compatible w/ pydantic v2 #209

schloerke opened this issue Jun 30, 2023 · 7 comments
Assignees
Labels
.epic .help wanted Extra attention is needed

Comments

@schloerke
Copy link
Contributor

https://docs.pydantic.dev/2.0/migration/#migration-guide

Related:

class _AutoDefault(_Base):
"""This hacky class allows creating Auto as a default option in Pages and Sections."""
__root__: Union[str, dict]
def __new__(cls, __root__: Union[str, dict]):
if isinstance(__root__, dict):
return Auto(**__root__)
return Auto(name=__root__)

ihnorton added a commit to TileDB-Inc/TileDB-Vector-Search that referenced this issue Jun 30, 2023
ihnorton added a commit to TileDB-Inc/TileDB-Vector-Search that referenced this issue Jun 30, 2023
@machow
Copy link
Owner

machow commented Jul 3, 2023

Ah, thanks! It seems pretty tricky to implement root so it's compatible with pydantic v1 and v2 😅. I tried an implementation on this PR, but am now running into another error...

#211

TypeError: `discriminator` can only be used with `Union` type with more than one variant

Seems to occure when Page.update_forward_refs() gets called....

@machow machow added the .help wanted Extra attention is needed label Jul 3, 2023
@machow
Copy link
Owner

machow commented Jul 3, 2023

I wonder if pydantic v2 expects that if there is a discriminator in a Union, then the other elements in the union must also be discriminators?

We have this piece of code...

ContentElement = Annotated[
    Union[Page, Section, Interlaced, Text, Auto], Field(discriminator="kind")
]
"""Entry in the contents list."""

ContentList = list[Union[ContentElement, Doc, _AutoDefault]]

Since Doc and _AutoDefault are just normal pydantic models, maybe it is considering each of them as Unions with only 1 variant?

edit: I tinkered a bit more and am pretty stumped

@machow
Copy link
Owner

machow commented Jul 3, 2023

Looks like it's this pydantic issue, and resolved in main a couple days ago:

pydantic/pydantic#6339

@machow machow added the .epic label Aug 7, 2023
@eitsupi
Copy link
Contributor

eitsupi commented Oct 8, 2023

Any update on this?
I was going to start using quartodoc but cannot install it because of this problem.

@mlysy
Copy link

mlysy commented Oct 10, 2023

From the pydantic README section Pydantic V1.10 vs. V2:

Pydantic V2 also ships with the latest version of Pydantic V1 built in so that you can incrementally upgrade your code base and projects: from pydantic import v1 as pydantic_v1.

Might it be a worthwhile first step to just keep the needed bits from V1 until a fully V2 solution is found?

@machow
Copy link
Owner

machow commented Oct 10, 2023

Oh wow -- I don't know how I missed that, but it seems like a very quick fix, thanks! Given this is way less effort than I was planning, I'll work on making the change this week..!

@machow machow self-assigned this Oct 10, 2023
@machow
Copy link
Owner

machow commented Nov 3, 2023

This should be resolved in https://github.com/machow/quartodoc/releases/tag/v0.6.4 (thanks to the tip above!)

@machow machow closed this as completed Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.epic .help wanted Extra attention is needed
Projects
Status: Done
Development

No branches or pull requests

4 participants