khalidmammadov commented on a change in pull request #18590:
URL: https://github.com/apache/airflow/pull/18590#discussion_r719102947



##########
File path: airflow/cli/commands/user_command.py
##########
@@ -159,27 +160,32 @@ def users_import(args):
     if not os.path.exists(json_file):
         raise SystemExit(f"File '{json_file}' does not exist")
 
-    users_list = None
+    users_list_ = None
     try:
         with open(json_file) as file:
-            users_list = json.loads(file.read())
+            users_list_ = json.loads(file.read())
     except ValueError as e:
         raise SystemExit(f"File '{json_file}' is not valid JSON. Error: {e}")
 
-    users_created, users_updated = _import_users(users_list)
+    users_created, users_updated = _import_users(users_list_)
     if users_created:
         print("Created the following 
users:\n\t{}".format("\n\t".join(users_created)))
 
     if users_updated:
         print("Updated the following 
users:\n\t{}".format("\n\t".join(users_updated)))
 
 
-def _import_users(users_list):
+def _import_users(users_list_: List[Dict[str, Any]]):
     appbuilder = cached_app().appbuilder
     users_created = []
     users_updated = []
 
-    for user in users_list:
+    for user in users_list_:
+        required_fields = ['username', 'firstname', 'lastname', 'email', 
'roles']
+        for field in required_fields:
+            if field not in user:

Review comment:
       That's correct, I was thinking about that and missed that part, was very 
late... it would still work if ww changed that back to dict.get but that would 
be implicit check and would yoeld misleading error about missing tole field. 
Will add explicit condition to check for an empty roles and add relevant test 
case




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to