Skip to content

Pydantic for domain models? #91

Description

@drforse

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'?

Activity

  1. hjwp commented on Oct 10, 2024

    @hjwp
    Contributor

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

  2. hjwp commented on Oct 10, 2024

    @hjwp
    Contributor

    let me know if you find a good solution!

  3. hjwp commented on Oct 10, 2024

    @hjwp
    Contributor

    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.

  4. hjwp commented on Oct 10, 2024

    @hjwp
    Contributor

    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 😊

  5. drforse commented on Oct 10, 2024

    @drforse
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions