hussein-awala commented on code in PR #72288:
URL: https://github.com/apache/airflow/pull/72288#discussion_r3889360442


##########
providers/fab/src/airflow/providers/fab/auth_manager/security_manager/override.py:
##########
@@ -1354,10 +1349,10 @@ def find_role(self, name) -> Role | None:
 
         :param name: the role name
         """
-        return 
self.session.scalars(select(self.role_model).filter_by(name=name)).unique().one_or_none()
+        return 
self.session.scalars(select(self.role_model).filter_by(name=name)).one_or_none()
 
     def get_all_roles(self) -> list[Role]:
-        return self.session.scalars(select(self.role_model)).unique().all()
+        return list(self.session.scalars(select(self.role_model)).all())

Review Comment:
   same here



##########
providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/services/users.py:
##########
@@ -85,7 +85,7 @@ def get_users(cls, *, order_by: str, limit: int, offset: int) 
-> UserCollectionR
         )
 
         stmt = select(User).order_by(ordering).offset(offset).limit(limit)
-        users = session.scalars(stmt).unique().all()
+        users = session.scalars(stmt).all()

Review Comment:
   This could work because `User.roles` uses `lazy="selectin"`, but the 
corresponding test was not updated



##########
providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/services/roles.py:
##########
@@ -95,7 +95,7 @@ def get_roles(cls, *, order_by: str, limit: int, offset: int) 
-> RoleCollectionR
         ordering = build_ordering(order_by, allowed={"name": Role.name, 
"role_id": Role.id})
 
         stmt = select(Role).order_by(ordering).offset(offset).limit(limit)
-        roles = session.scalars(stmt).unique().all()
+        roles = session.scalars(stmt).all()

Review Comment:
   `Role.permissions` is configured with `lazy="joined"` in the FAB model. 
Consequently, this plain `select(Role)` includes a joined eager-loaded 
collection, and SQLAlchemy requires `unique()` before consuming the result. 
Calling `.all()` directly raises `InvalidRequestError`. Did you test it?



-- 
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