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

412 PRECONDITION FAILED when _etag is correct #1465

Open
xibriz opened this issue Feb 8, 2022 · 1 comment
Open

412 PRECONDITION FAILED when _etag is correct #1465

xibriz opened this issue Feb 8, 2022 · 1 comment

Comments

@xibriz
Copy link

xibriz commented Feb 8, 2022

Expected Behavior: 204 NO CONTENT

Actual Behavior: 412 PRECONDITION FAILED

If SOFT_DELETE is set to True on a global level and an endpoint is defined without a schema, it becomes impossible to delete.

Example endpoint:

my_endpoint = {
    'cache_control': 'no-store',
    'resource_methods': ['GET', 'POST'],
    'item_methods': ['DELETE'],
    'allow_unknown': True,
    'schema': {}
}

I found two work arounds:

  1. Add 'soft_delete': False to the configuration
  2. Set 'allow_unknown': False and define a schema

Either the response should be someting else becase the _etag is correct or the bug should be fixed.

Environment

  • Python version: 3.8.10
  • Eve version: 1.1.5
@ljluestc
Copy link

from eve import Eve

app = Eve()

@app.route('/<resource_name>/<item_id>', methods=['DELETE'])
def custom_delete(resource_name, item_id):
# Check if the resource allows soft delete and has no schema defined
if app.config.get('SOFT_DELETE', False) and resource_name in app.config['DOMAIN'] and 'schema' not in app.config['DOMAIN'][resource_name]:
# Return a custom error response for the 412 status code
response = {
'_status': 'ERR',
'_error': {
'code': 412,
'message': 'Soft delete is enabled, but resource has no schema defined. Please define a schema or disable soft delete.'
}
}
return response, 412

# Continue with regular item deletion logic
# ...

if name == 'main':
app.run()

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