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 for domain models? #91

Open
drforse opened this issue Oct 7, 2024 · 5 comments
Open

Pydantic for domain models? #91

drforse opened this issue Oct 7, 2024 · 5 comments

Comments

@drforse
Copy link

drforse commented Oct 7, 2024

Hello. I really liked this book, it gives a fresh (for me) perspective at coding a web application, and it looks fantastic, very well written, not too difficult to understand. I finished the part 1 a couple of hours ago, it turned my perspective upside down, and I decided to give my new knowledge a try, just writing a small web service. And I encountered a problem: if I want to use pydantic to write my domain models, when I apply the SQLAlchemy mapper on them, the models stop working, they simply throw error at initializing. I really love pydantic, but I also ain't sure it's worth implementing smth like in django appendix just because I wanna use pydantic insteadof dataclasses and just classes.

The error:
AttributeError: 'User' object has no attribute 'pydantic_private'. Did you mean: 'pydantic_complete'?

@hjwp
Copy link
Contributor

hjwp commented Oct 10, 2024

I like pydantic too! but i've never tried it with the sqla mapper. maybe something more manual is the only way to go...

@hjwp
Copy link
Contributor

hjwp commented Oct 10, 2024

let me know if you find a good solution!

@hjwp
Copy link
Contributor

hjwp commented Oct 10, 2024

I would say - don't be afraid of boilerplate like this. a dumb function that maps a sqlalchemy row-dictionary to a pydantic class in a really mechanical way might feel really tedious and verbose, but it really isn't that much of a maintenance burden.

@hjwp
Copy link
Contributor

hjwp commented Oct 10, 2024

oh and also-by-the-way -- if you enjoyed the book, i don't suppose you'd have time to write a quick review online somewhere? on amazon or goodreads or wherever you like to put reviews? they really help 😊

@drforse
Copy link
Author

drforse commented Oct 10, 2024

oh and also-by-the-way -- if you enjoyed the book, i don't suppose you'd have time to write a quick review online somewhere? on amazon or goodreads or wherever you like to put reviews? they really help 😊

I'd be glad to leave a review everywhere I can, but I don't know where, could you give the urls?

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

2 participants