jfinkels / flask-restless

NO LONGER MAINTAINED - A Flask extension for creating simple ReSTful JSON APIs from SQLAlchemy models.
https://flask-restless.readthedocs.io
GNU Affero General Public License v3.0
1.02k stars 301 forks source link

Refresh SQLAlchemy object after creation in POST #647

Open jfinkels opened 7 years ago

jfinkels commented 7 years ago

Partially fixes issue #630.

What change does this make? This adds Sesson.refresh(obj) call to the SQLAlchemy object created during a POST request. Calling refresh() after the object has been added and the session flushed causes any timezone-aware datetime attribute deserialized from the incoming request to be re-read from the database as timezone-naive datetime if the database is configured that way.

How does this affect the user? This corrects a bug in which the response to a POST request incorrectly still showed the timezone-aware datetime attribute even though the database was storing only the timezone-naive datetime attribute.