Mobile Users Bulk Upload and Multiple Billing Accounts Error

Hi,

i. Django returns the following error while importing bulk mobile users

2024-02-19 12:58:56,789 ERROR [django.request] Internal Server Error: /a/fmoh-echis/settings/users/commcare/upload/poll/dl-0e0c61921dfd4e1ca61a48af189f04a6/
Traceback (most recent call last):
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/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/2024-02-19_10.51/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/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/sentry_sdk/integrations/django/views.py", line 85, in sentry_wrapped_callback
    return callback(request, *args, **kwargs)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/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/2024-02-19_10.51/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/2024-02-19_10.51/corehq/apps/domain/decorators.py", line 115, in _inner
    return call_view()
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/corehq/apps/domain/decorators.py", line 88, in call_view
    def call_view(): return view_func(req, domain_name, *args, **kwargs)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/corehq/apps/users/decorators.py", line 47, in _inner
    return view_func(request, domain, *args, **kwargs)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/corehq/apps/users/views/mobile/users.py", line 1159, in dispatch
    return super(CommcareUserUploadJobPollView, self).dispatch(request, *args, **kwargs)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/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/2024-02-19_10.51/corehq/apps/domain/decorators.py", line 115, in _inner
    return call_view()
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/corehq/apps/domain/decorators.py", line 88, in call_view
    def call_view(): return view_func(req, domain_name, *args, **kwargs)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/corehq/apps/domain/decorators.py", line 196, in dispatch
    return super(LoginAndDomainMixin, self).dispatch(*args, **kwargs)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/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/2024-02-19_10.51/corehq/apps/users/views/__init__.py", line 1302, in get
    return render(request, 'users/mobile/partials/user_upload_status.html', context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/sentry_sdk/integrations/django/templates.py", line 96, in render
    return real_render(request, template_name, context, *args, **kwargs)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 170, in render
    return self._render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/defaulttags.py", line 315, in render
    return nodelist.render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/defaulttags.py", line 315, in render
    return nodelist.render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/defaulttags.py", line 166, in render
    values = self.sequence.resolve(context, ignore_failures=True)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 671, in resolve
    obj = self.var.resolve(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 796, in resolve
    value = self._resolve_lookup(context)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/template/base.py", line 858, in _resolve_lookup
    current = current()
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/corehq/apps/users/views/utils.py", line 73, in errors
    errors.append('{username}: {flag}'.format(**row))
KeyError: 'username'

ii. Multiple billing accounts

2024-02-19 11:37:43,474 ERROR [accounting] [BILLING] Multiple billing accounts showed up for the domain 'fmoh-echis'. The latest one was served, but you should reconcile very soon.
Traceback (most recent call last):
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/corehq/apps/accounting/models.py", line 498, in _get_account_by_created_by_domain
    return cls.objects.get(created_by_domain=domain)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/cchq/www/echis/releases/2024-02-19_10.51/python_env-3.9/lib/python3.9/site-packages/django/db/models/query.py", line 439, in get
    raise self.model.MultipleObjectsReturned(

Hi, @sirajhassan .

Could you please clarify when exactly you're getting the Multiple billing accounts error? Is that also when you bulk import the mobile workers?

Hi @CharlSmit,

Multiple billing accounts message is appearing in the Django log frequently, not when importing the mobile users.

Thanks for clarifying. I'll focus on the failing mobile worker import first.

Have you confirmed that the excel sheet containing the mobile workers' details have usernames specified?

Thank you so much @CharlSmit, the issue was related to username. Maybe some users were existing in the system.

Great! Then I presume it's resolved?

Hi @CharlSmit,

Yes, new users are imported. Observed that the error is generated when try to import existing users.

Thank you,