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

[FR] Add __post_init__ equivalent #689

Open
Zocker1999NET opened this issue Jul 7, 2023 · 2 comments
Open

[FR] Add __post_init__ equivalent #689

Zocker1999NET opened this issue Jul 7, 2023 · 2 comments

Comments

@Zocker1999NET
Copy link

It would be great to have something for Pony entities which works similar to the __post_init__ method for dataclasses, allowing to modify or further set up an entity object directly after it was created, without requiring to override Pony’s `init and then call it again with the same arguments.

This should be relatively easy to implement. However, while looking through Pony’s code, I don’t seem to get where this call should happen.

@JoshYuJump
Copy link
Contributor

Maybe you can take a look at hooks
https://docs.ponyorm.org/api_reference.html#entity-hooks

@Zocker1999NET
Copy link
Author

Zocker1999NET commented Jul 29, 2024

The entity hooks were not helpful in my case as those (if I understand them correctly) trigger when interacting with the database. However, I wanted to adjust the defaults of some properties depending on other, given attributes & I would prefer if those dynamic defaults would already be applied before the object is stored into the DB.

(I just saw your suggestion again & thought I could answer it through I do not need a __post_init__ anymore but I think this might still be helpful.)

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