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

422 UNPROCESSABLE ENTITY when using user_id and data_relation on PATCH #1472

Open
xibriz opened this issue Mar 29, 2022 · 1 comment
Open

Comments

@xibriz
Copy link

xibriz commented Mar 29, 2022

Expected Behavior: 200 OK

Actual Behavior: 422 UNPROCESSABLE ENTITY

If using set_request_auth_value on a schema and having defined a data_relation to a schema that is not using any auth value,
a PATCH operation will fail with the follwoing error:

value 'XXX' must exist in resource 'YYY', field '_id'

POST works fine.

The only workaround is not to define any data_relation.

According to my research, the _filter variable contains the user_id in an $and condition when PATCH but not on POST.

datasource, filter_, projection, _ = self._datasource_ex(

Environment

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

from eve import Eve

app = Eve()

Define the schemas

schema_with_auth = {
'author': {
'type': 'objectid',
'data_relation': {
'resource': 'users',
'field': '_id',
'embeddable': True,
}
}
}

schema_without_auth = {
'name': {
'type': 'string',
}
}

Apply the schemas to appropriate resources

app.config['DOMAIN'] = {
'articles': {
'schema': schema_with_auth,
'resource_methods': ['GET', 'POST', 'PATCH'],
'item_methods': ['GET', 'PATCH'],
},
'users': {
'schema': schema_without_auth,
'resource_methods': ['GET', 'POST'],
'item_methods': ['GET'],
},
}

Patch request will fail without this workaround

def fix_patch_request(resource, request, lookup):
if request.method == 'PATCH':
app.auth.set_request_auth_value(resource, request, lookup)

app.on_pre_PATCH += fix_patch_request

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