From 2b59119eca64c880acba025dd81adebbd52d092c Mon Sep 17 00:00:00 2001 From: Carlos Mesquita Date: Sun, 8 Sep 2024 02:29:56 +0100 Subject: [PATCH 1/3] And this is why llm code shouldn't be copy pasted blindly --- modules/batch_users/service.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/batch_users/service.py b/modules/batch_users/service.py index 18155cf..bd6be73 100644 --- a/modules/batch_users/service.py +++ b/modules/batch_users/service.py @@ -44,7 +44,7 @@ class BatchUsers: result = self._upload_users('./tmp', file_name) if result.returncode != 0: - error_msg = f"Couldn't upload users. Failed to run command firebase auth import -> ```cmd {result.stderr}```" + error_msg = f"Couldn't upload users. Failed to run command firebase auth import -> ```cmd {result.stdout}```" self._logger.error(error_msg) return error_msg @@ -209,14 +209,14 @@ class BatchUsers: if corporate_user: self._db.codes.update_one( {"id": code}, - {"$set": {"creator": corporate_user.id}}, + {"$set": {"creator": corporate_user["id"]}}, upsert=True ) group_type = "Students" if user.type == "student" else "Teachers" group = self._db.groups.find_one( { - "admin": corporate_user.id, + "admin": corporate_user["id"], "name": group_type } ) @@ -226,13 +226,13 @@ class BatchUsers: if user_id not in participants: participants.append(user_id) self._db.groups.update_one( - {"id": group.id}, + {"id": group["id"]}, {"$set": {"participants": participants}} ) else: group = { - 'admin': corporate_user.id, + 'admin': corporate_user["id"], 'id': str(uuid.uuid4()), 'name': group_type, 'participants': [user_id], @@ -244,14 +244,14 @@ class BatchUsers: def _assign_user_to_group_by_name(self, user: UserDTO, maker_id: str): user_id = str(user.id) - group = self._db.groups.find_one( + groups = list(self._db.groups.find( { "admin": maker_id, - "name": user.group_name.strip() + "name": user.groupName.strip() } - ) + )) - if group: + if len(groups) == 0: new_group = { 'id': str(uuid.uuid4()), 'admin': maker_id, @@ -261,10 +261,11 @@ class BatchUsers: } self._db.groups.insert_one(new_group) else: - participants = group.participants + group = groups[0] + participants = group["participants"] if user_id not in participants: participants.append(user_id) self._db.groups.update_one( - {"id": group.id}, + {"id": group["id"]}, {"$set": {"participants": participants}} ) From c004d9c83cf6d9590bfb33b968e763b69c8188c4 Mon Sep 17 00:00:00 2001 From: Carlos Mesquita Date: Sun, 8 Sep 2024 21:47:02 +0100 Subject: [PATCH 2/3] Pydantic was causing validation errors when passportID was an int --- modules/batch_users/batch_users.py | 2 +- modules/batch_users/service.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/batch_users/batch_users.py b/modules/batch_users/batch_users.py index 6e94e0c..55ee6f3 100644 --- a/modules/batch_users/batch_users.py +++ b/modules/batch_users/batch_users.py @@ -21,7 +21,7 @@ class UserDTO(BaseModel): passwordSalt: str groupName: Optional[str] = None corporate: Optional[str] = None - studentID: Optional[str] = None + studentID: Optional[str | int] = None expiryDate: Optional[str] = None demographicInformation: Optional[DemographicInfo] = None diff --git a/modules/batch_users/service.py b/modules/batch_users/service.py index bd6be73..60861ba 100644 --- a/modules/batch_users/service.py +++ b/modules/batch_users/service.py @@ -55,7 +55,11 @@ class BatchUsers: @staticmethod def _map_to_batch(request_data: Dict) -> BatchUsersDTO: - users: list[UserDTO] = [UserDTO(**user) for user in request_data["users"]] + users_list = [{**user} for user in request_data["users"]] + for user in users_list: + user["studentID"] = str(user["studentID"]) + + users: list[UserDTO] = [UserDTO(**user) for user in users_list] return BatchUsersDTO(makerID=request_data["makerID"], users=users) @staticmethod From aa1433e9ea36f72eb823ef71ff727ef9c095f03b Mon Sep 17 00:00:00 2001 From: Carlos Mesquita Date: Sun, 22 Sep 2024 23:25:54 +0100 Subject: [PATCH 3/3] UUID wasn't being converted to string, before it used the firebase id and when transitioning to mongo this bug was introduced --- modules/training_content/service.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/training_content/service.py b/modules/training_content/service.py index e6162d7..e9b3280 100644 --- a/modules/training_content/service.py +++ b/modules/training_content/service.py @@ -40,7 +40,7 @@ class TrainingContentService: for area in training_content.weak_areas: weak_areas["weak_areas"].append(area.dict()) - new_id = uuid.uuid4() + new_id = str(uuid.uuid4()) training_doc = { 'id': new_id, 'created_at': int(datetime.now().timestamp() * 1000), @@ -224,8 +224,6 @@ class TrainingContentService: exam_map[session_key]["score"] = round((exam_total_correct / exam_total_questions) * 100) exam_map[session_key]["module"] = module - with open('exam_result.json', 'w') as file: - json.dump({"exams": exercises}, file, indent=4) return {"exams": exercises}, exam_map