# Unable to delete mobile user from specific location

**URL:** <https://forum.dimagi.com/t/unable-to-delete-mobile-user-from-specific-location/9202>\
**Category:** Developers\
**Created:** [August 17, 2022, 4:06pm UTC](https://forum.dimagi.com/t/unable-to-delete-mobile-user-from-specific-location/9202 "2022-08-17T16:06:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![demis08](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/demis08/32/1234_2.png) [@demis08](https://forum.dimagi.com/u/demis08)\
**Post date:** [August 17, 2022, 4:06pm UTC](https://forum.dimagi.com/t/unable-to-delete-mobile-user-from-specific-location/9202/1 "2022-08-17T16:06:36Z")

</div>

Hello,

I was trying to delete(detach) the mobile user from the wrongly placed location, as shown below

 ![Screen Shot 2022-08-17 at 7.01.56 PM](https://dimagi.b-cdn.net/uploads/default/original/2X/3/32f2b756f15f0bf27605b43344dba0501409e227.png)

The following error displayed after click on `update location membership`

> 2022-08-17 15:57:45,793 ERROR [django.request] Internal Server Error: /a/fmoh-echis/settings/locations/fddeef5f386147b18e212c83ba8512f1/  
> Traceback (most recent call last):  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/blobs/s3db.py", line 175, in maybe\_not\_found  
> yield  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/blobs/s3db.py", line 99, in get  
> resp = self.\_s3\_bucket().Object(key).get()  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/boto3/resources/factory.py", line 580, in do\_action  
> response = action(self, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/boto3/resources/action.py", line 88, in **call**  
> response = getattr(parent.meta.client, operation\_name)(\*args, \*\*params)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/botocore/client.py", line 508, in \_api\_call  
> return self.\_make\_api\_call(operation\_name, kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/botocore/client.py", line 915, in \_make\_api\_call  
> raise error\_class(parsed\_response, operation\_name)  
> botocore.errorfactory.NoSuchKey: An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.
> 
> During handling of the above exception, another exception occurred:  
> Traceback (most recent call last):  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/form\_processor/models/forms.py", line 674, in get\_xml  
> return self.get\_attachment('form.xml')  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/form\_processor/models/attachment.py", line 258, in get\_attachment  
> with attachment.open() as content:  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/blobs/models.py", line 107, in open  
> return db.get(meta=self)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/ex-submodules/dimagi/utils/retry.py", line 31, in retry  
> return func(\*args, \*\*kw)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/blobs/s3db.py", line 99, in get  
> resp = self.\_s3\_bucket().Object(key).get()  
> File "/usr/lib/python3.9/contextlib.py", line 137, in **exit**  
> self.gen.throw(typ, value, traceback)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/blobs/s3db.py", line 181, in maybe\_not\_found  
> raise throw  
> corehq.blobs.exceptions.NotFound: 7ca7d0f9090240baa51f658dd16897d5
> 
> Traceback (most recent call last):  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner  
> response = get\_response(request)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in \_get\_response  
> response = wrapped\_callback(request, \*callback\_args, \*\*callback\_kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/sentry\_sdk/integrations/django/views.py", line 67, in sentr  
> y\_wrapped\_callback  
> return callback(request, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view  
> return self.dispatch(request, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/hqwebapp/decorators.py", line 70, in \_wrapped  
> return view\_func(\*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/django/utils/decorators.py", line 43, in \_wrapper  
> return bound\_method(\*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/locations/views.py", line 160, in new\_fn  
> return view\_fn(request, domain, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/django/utils/decorators.py", line 43, in \_wrapper  
> return bound\_method(\*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/domain/decorators.py", line 111, in \_inner  
> return call\_view()  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/domain/decorators.py", line 84, in call\_view  
> def call\_view(): return view\_func(req, domain\_name, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/django\_prbac/decorators.py", line 38, in wrapped  
> return fn(request, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/domain/decorators.py", line 111, in \_inner  
> return call\_view()  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/domain/decorators.py", line 84, in call\_view  
> def call\_view(): return view\_func(req, domain\_name, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/users/decorators.py", line 45, in \_inner  
> return view\_func(request, domain, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/locations/permissions.py", line 337, in \_inner  
> return view\_fn(request, domain, loc\_id, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/locations/views.py", line 700, in dispatch  
> return super(EditLocationView, self).dispatch(request, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/django/utils/decorators.py", line 43, in \_wrapper  
> return bound\_method(\*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/domain/decorators.py", line 111, in \_inner  
> return call\_view()  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/domain/decorators.py", line 84, in call\_view  
> def call\_view(): return view\_func(req, domain\_name, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/domain/decorators.py", line 181, in dispatch  
> return super(LoginAndDomainMixin, self).dispatch(\*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/django/views/generic/base.py", line 98, in dispatch  
> return handler(request, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/django/utils/decorators.py", line 43, in \_wrapper  
> return bound\_method(\*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/locations/views.py", line 96, in func\_wrapper  
> return func(request, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/locations/views.py", line 834, in post  
> return self.users\_form\_post(request, \*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/locations/views.py", line 810, in users\_form\_post  
> self.users\_form.save()  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/locations/forms.py", line 510, in save  
> self.unassign\_users(to\_remove)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/locations/forms.py", line 482, in unassign\_users  
> CommCareUser.wrap(doc).unset\_location\_by\_id(self.location.location\_id, fall\_back\_to\_next=True)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/users/models.py", line 2057, in unset\_location\_by\_id  
> self.unset\_location(fall\_back\_to\_next)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/users/models.py", line 2035, in unset\_location  
> self.set\_location(SQLLocation.objects.get(location\_id=new\_primary\_location\_id))  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/users/models.py", line 1995, in set\_location  
> self.create\_location\_delegates([location])  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/users/models.py", line 2153, in create\_location\_delegates  
> self.clear\_location\_delegates()  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/apps/users/models.py", line 2146, in clear\_location\_delegates  
> safe\_hard\_delete(mapping)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/ex-submodules/casexml/apps/case/cleanup.py", line 95, in safe\_hard\_delete  
> case\_updates = get\_case\_updates(form)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/ex-submodules/casexml/apps/case/xform.py", line 245, in get\_case\_updates  
> [case\_update\_from\_block(cb) for cb in extract\_case\_blocks(xform)],  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/ex-submodules/casexml/apps/case/xform.py", line 200, in extract\_case\_blocks  
> form = doc.form\_data  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/memoized.py", line 20, in \_memoized  
> cache[key] = value = fn(\*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/form\_processor/models/forms.py", line 593, in form\_data  
> xml = self.get\_xml()  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/python\_env-3.9/lib/python3.9/site-packages/memoized.py", line 20, in \_memoized  
> cache[key] = value = fn(\*args, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2022-08-14\_17.31/corehq/form\_processor/models/forms.py", line 676, in get\_xml  
> raise MissingFormXml(self.form\_id)  
> corehq.form\_processor.exceptions.MissingFormXml: 170101f9fa1f41699e367cbf8fbcd307

---

<div class="post-metadata">

**Author:** ![Ethan\_Soergel](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/ethan_soergel/32/543_2.png) [@Ethan\_Soergel](https://forum.dimagi.com/u/Ethan_Soergel)\
**Post date:** [August 17, 2022, 5:16pm UTC](https://forum.dimagi.com/t/unable-to-delete-mobile-user-from-specific-location/9202/2 "2022-08-17T17:16:27Z")

</div>

This is kind of a weird error. When assigning users to locations, a "delegate" case is created (case type `user-owner-mapping-case`), for use in some particular app workflows. What's happening here is you are attempting to remove a user from a location, which triggers a hard deletion of this case. In processing this deletion, it looks up the forms which modify that case, but one of those forms is missing XML.

I'm not certain why this XML is missing - it could be a problem with your blobdb (S3, riak, or similar), where that form XML is stored. You can find the case ID in question by running this command in a shell session:

```auto
>>> CommCareUser.get_by_username('USERNAME@DOMAIN.commcarehq.org').get_location_map_case().case_id

```

That might help get started troubleshooting.
