You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the models and relationships as shown below. As you can see, the parent_id column is a non-nullable ForeignKey. When I attempt to delete a parent for one of these children, the response is a 500 Internal Server Error with HTML that includes the actual SQL error.
For proper API behavior, an underlying SQL error should produce a 4xx error that returns the SQL error the same way that a validation error would be produced by Eve, i.e. with the _error property.
To implement this, I believe the sqlalchemy.exc.IntegrityError should be caught by Eve-SQLAlchemy and wrapped up in an Eve error response format. I'm happy to take this, if the approach is valid.
Edit: To clarify, the SQL error is expected. It is caused by the cascade default when dropping foreign keys. This shouldn't be an Internal Server Error, though. The fault should be signaled to the client.
The text was updated successfully, but these errors were encountered:
I agree that in cases it's the client's fault, we should use 4xx error codes. But some SQL errors will really be internal and the client cannot do anything about that - those should stay 5xx errors in my opinion.
Thanks for getting back @dkellner . I agree that some will be true errors, and we shouldn't blanket catch and return a 4xx. However, for a sqlalchemy.exc.IntegrityError exception, that is clearly the client (or API, I suppose) offending the underlying database. In my example where a relationship shouldn't be broken because of the non-nullable ForeignKey, that is actually a bad request by the client. A 4xx making this clear to the client should be the expected behavior. IMO, this is actually similar to any non-nullable constraint. However, Eve provides the validation to make a field non-nullable at the API layer. It does not do this for relationships, as far as I know. What do you think?
Yes, I totally agree. I just wanted to make sure we're still making a distinction between errors the user/client can actually handle to the ones outside of its responsibility.
Catching the exception and handling it sounds like a good approach to me.
Hi all,
I have the models and relationships as shown below. As you can see, the
parent_id
column is a non-nullable ForeignKey. When I attempt to delete a parent for one of these children, the response is a500 Internal Server Error
with HTML that includes the actual SQL error.For proper API behavior, an underlying SQL error should produce a
4xx
error that returns the SQL error the same way that a validation error would be produced by Eve, i.e. with the_error
property.To implement this, I believe the
sqlalchemy.exc.IntegrityError
should be caught by Eve-SQLAlchemy and wrapped up in an Eve error response format. I'm happy to take this, if the approach is valid.Edit: To clarify, the SQL error is expected. It is caused by the cascade default when dropping foreign keys. This shouldn't be an Internal Server Error, though. The fault should be signaled to the client.
The text was updated successfully, but these errors were encountered: