-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Allow for non-nullable fields to be handled by the database #196
Comments
Thanks for the detailed question, I appreciate the effort! I think the problem is as follows:
The standard way in SQLAlchemy to solve this is is using the A new extension property (proposed: I just did a POC and this works. Without it, constructing without An additional recommendation would be to mark |
@jdkandersson That sounds ideal! And yes, that is a great solution. I was thinking something along those lines. |
One thing I should have noted at the time, a temporary work around is to use the |
Oh wow, yes, that's a great idea. I don't think I knew enough about server_default at the time to understand, but your explanation makes sense! |
Hi! Hopefully there's a good answer to this. I put in as much information as I could to be easy to replicate.
Summary
If our database is responsible for setting the value of a column, we do not want to set that column via SQLAlchemy; instead, we would like the database to handle it via trigger. We do not want the model generated to set the value to
None
.This is especially useful in cases where we want timestamps, and we wish them to be handled by the database.
Setup (3 files)
1:
openapi.yml
2:
main.py
3: A sqlite database:
petstore.db
To setup the project...
Copy all 3 files above into the main
oa_issue
folder. Then run the script.Results
You receive an error from the database.
The error happens because the model is setting the
created_at
column toNone
explicitly. We don't get the same error on theid
column, of course, because OpenAlchemy understands that this is auto-generated by the database, and sets the internal flag ofx-generated
on that attribute.Just before the commit, looking in a debugger,
Ideally, we'd like the same thing for the
created_at
column.Question
Is there any way to get around this, while still keeping the
created_at
column in the
openapi.yml
file?The text was updated successfully, but these errors were encountered: