TWSD-1221 - Getting "Internal error" while creating Admin user from Webui || AS-25874 || JHSSDC

Review Request #1103 — Created Oct. 20, 2025 and submitted

shuinvy
AVX2
rel_avx_2_7_5
TWSD-1221
ngurunathan, stevenku, timlai, wli

Fix KeyError issue for _get_two_factor function

Our original mechanism will get all data if the field is DelayedQuery.
For the error message:

  ERROR - Internal Server Error: /apv.fcgi/api/avx/system/user_mgmt/Administrator/_add
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 113, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/ca/webui/htdocs/new/src/hive/router.py", line 253, in hive_ajax_router
    response = HttpResponse(ModelAjaxHandler(request, sess, app, model, action).render())
  File "/ca/webui/htdocs/new/src/hive/model/ajax.py", line 47, in render
    return getattr(self, self.action)(**request_dict)
  File "/ca/webui/htdocs/new/src/hive/model/ajax.py", line 176, in add
    self.manager.insert(new_obj)
  File "/ca/webui/htdocs/new/src/hive/model/manager.py", line 218, in insert
    result = self._insert(model_instance)
  File "/ca/webui/htdocs/new/src/avx/models/system/user_mgmt/__init__.py", line 91, in _insert
    data = instance.get_field_dict()
  File "/ca/webui/htdocs/new/src/hive/model/base.py", line 587, in get_field_dict
    val = mgr.get_field_by_instance(self, f.attname)
  File "/ca/webui/htdocs/new/src/hive/model/manager.py", line 479, in get_field_by_instance
    value = getattr(self, '_get_'+field_name)(the_pk_dict)
  File "/ca/webui/htdocs/new/src/avx/models/system/user_mgmt/__init__.py", line 176, in _get_two_factor
    return True if result["two_factor"] == "on" else False
KeyError: 'two_factor'

Even we are get/add/update data only,
it will call get fields function,
so it called _get_two_factor function.
And we call this function before we add the new administrator account,
the cli:

show webui twofactor user {username}

will return empty.

so this line:

return True if result["two_factor"] == "on" else False

raise KeyError.

I use

return result.get("two_factor") == "on"

to prevent the KeyError issue.

That is,
if there is no certain account,
the two factor is empty,
so the _get_two_factor return False.
only when there is certain account and the two factor is "on",
the _get_two_factor function return True.

timlai
  1. Ship It!
  2. 
      
stevenku
  1. Ship It!
  2. 
      
shuinvy
Review request changed

Status: Closed (submitted)

wli
  1. Ship It!
  2. 
      
Loading...