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

Pydantic V2 support #310

Open
agrewal opened this issue Mar 13, 2024 · 4 comments
Open

Pydantic V2 support #310

agrewal opened this issue Mar 13, 2024 · 4 comments

Comments

@agrewal
Copy link

agrewal commented Mar 13, 2024

Is your feature request related to a problem? Please describe.
My models are all in pydantic V2. These cannot be intermixed with V1 models. Do you have plans to add support for v2 models?

Describe the solution you'd like
Optionally support V2 models in pydantic for Calendar, Event etc.

Describe alternatives you've considered
Currently I have split V1 models separately, so I have a combination of both in the codebase.

Additional context

@allenporter
Copy link
Owner

Hi -- appreciate reaching out here. Perhaps there are couple topics to unwind:

  1. Use of pydantic in ical should be an implementation detail not really a feature that is consumed by the library. Can you explain how you're using the data model? I'm wondering if there is an alternative way the APIs could be exposed to make this easier (e.g. only exposing dataclasses and not inheriting pydantic models)

  2. To more directly answer the question, the primary consumer of this library requires v1 and can't upgrade to v2 until many other libraries have been upgraded. For now, this continues to use the v1 stubs when v2 is installed for compatibility. I'm not sure there is a path forward without forking.

Given the pain that pydantic caused through its upgrade path to v2 (which is somewhat hostile), I'm more inclined to move away from pydantic and on to another libraries rather than add lots of workaround or duplicate the model hierarchy with both v1 and v2 models.

Happy to discuss and entertain other approaches. This library does not have that many consumers so its not super painful to make large changes.

@agrewal
Copy link
Author

agrewal commented Mar 17, 2024 via email

@dwreeves
Copy link

@allenporter I understand that Pydantic 2.0 migration is annoying, but I use this library mainly to serialize ics files to JSON so I can dump it into a database. 😄 So using Pydantic as the serialization backend is perfect for me.

Plus, really not a fan of the other 2 alternatives in the Python ecosystem. ics.py is untyped, makes a few weird decisions like using set()s in inappropriate places, and doesn't serialize to JSON well; icalendar among other issues isn't even fully RFC 5545 compliant and thus it causes issues in my data pipeline for perfectly valid ics files.

If you need help with any Pydantic migration work, let me know. My use case essentially requires Pydantic and I hope you consider keeping it, and I can chip in if you need resources to keep using Pydantic.

@allenporter
Copy link
Owner

I could definitely use help on pedantic migration. However I need to use this library in code based that don't yet support v2 (home assistant). Given pydantic made this weird upgrade choice I'm not sure what we can do in the mean time.

So maybe the most helpful thing is to upgrade all home assistant dependencies to v2 with v1 stubs :) it's made progress though so it's not starting from nothing.

Agree with your assessments of the choices of other libraries, that prompted me to make this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants