Project

General

Profile

Bug #23934

Fix traceback when trying to PUT nonexistent object

Added by Mike Gering over 1 year ago. Updated 12 months ago.

Status:
Resolved
Priority:
Important
Assignee:
William Grzybowski
Category:
Middleware
Target version:
Seen in:
Sprint:
Severity:
New
Backlog Priority:
Reason for Closing:
Reason for Blocked:
Needs QA:
No
Needs Doc:
Yes
Needs Merging:
Yes
Needs Automation:
No
Support Suite Ticket:
n/a
Hardware Configuration:
ChangeLog Required:
No

Description

Using the API to update the ssh key for a user, the server throws an exception and returns an error response:

Sorry, this request could not be processed. Please try again later.
data = {
        'bsdusr_sshpubkey': ssh_key,
    }
url = "http://%s/api/v1.0/account/users/%d/" % (fn_host, user_data['bsdusr_uid'])
response = requests.put(url, auth=get_auth(), json=data).json()    

The stacktraces in the log:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/tastypie/resources.py", line 201, in wrapper
    response = callback(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/tastypie/resources.py", line 441, in dispatch_detail
    return self.dispatch('detail', request, **kwargs)
  File "/usr/local/www/freenasUI/../freenasUI/api/utils.py", line 234, in dispatch
    request_type, request, *args, **kwargs
  File "/usr/local/lib/python2.7/site-packages/tastypie/resources.py", line 464, in dispatch
    response = method(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/tastypie/resources.py", line 1437, in put_detail
    updated_bundle = self.obj_create(bundle=bundle, **self.remove_api_resource_names(kwargs))
  File "/usr/local/lib/python2.7/site-packages/tastypie/resources.py", line 2104, in obj_create
    return self.save(bundle)
  File "/usr/local/www/freenasUI/../freenasUI/api/utils.py", line 353, in save
    api_validation=True,
  File "/usr/local/www/freenasUI/../freenasUI/account/forms.py", line 298, in __init__
    self.fields['bsdusr_group'].initial = self.instance.bsdusr_group
  File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 326, in __get__
    "%s has no %s." % (self.field.model.__name__, self.field.name))
DoesNotExist: bsdUsers has no bsdusr_group.

I've tried this with different users, builtin (root), and non-builtin.

Associated revisions

Revision ca4008ff (diff)
Added by William Grzybowski over 1 year ago

fix(api): return 404 when trying to PUT nonexistent entry

Previously it would try to create the entry.

Ticket: #23934

History

#1 Updated by William Grzybowski over 1 year ago

  • Status changed from Unscreened to 15

For which user are you trying?

Can you do it from GUI?

#2 Updated by Mike Gering over 1 year ago

I've tried for user 0 and for user 1000 (me). Both work from the GUI.

I've also tried using different json data:

  1. Initialized with all the fields from the user retrieved by finding it in /account/users
  2. Added the bsdusr_group

The trace info is the same in all cases.

#3 Updated by William Grzybowski over 1 year ago

  • Status changed from 15 to Screened
  • Priority changed from No priority to Important
  • Target version set to 11.0

#4 Updated by William Grzybowski over 1 year ago

You're using the wrong id, its "id", not "bsdusr_uid"

#5 Updated by William Grzybowski over 1 year ago

  • Subject changed from Cannot update ssh public key via API to Traceback trying to PUT nonexistent object

Real error here is that it tries to create an entry if it does not exist.

#6 Updated by William Grzybowski over 1 year ago

  • Status changed from Screened to Resolved
  • Target version changed from 11.0 to 11.1

#7 Updated by Mike Gering over 1 year ago

Thanks -- it works as expected now that I'm using the correct field

#8 Updated by Dru Lavigne about 1 year ago

  • Subject changed from Traceback trying to PUT nonexistent object to Fix traceback when trying to PUT nonexistent object

#9 Updated by Dru Lavigne about 1 year ago

  • Target version changed from 11.1 to 11.1-BETA1

#10 Updated by Joe Maloney 12 months ago

  • Needs QA changed from Yes to No
  • QA Status deleted (Not Tested)

Also available in: Atom PDF