@@ -153,6 +153,10 @@ def is_sid_requested(self) -> bool:
153153 def is_guid_requested (self ) -> bool :
154154 return self .all_attrs or "objectguid" in self .requested_attrs
155155
156+ @property
157+ def is_objectclass_requested (self ) -> bool :
158+ return self .all_attrs or "objectclass" in self .requested_attrs
159+
156160 @cached_property
157161 def all_attrs (self ) -> bool :
158162 return "*" in self .requested_attrs or not self .requested_attrs
@@ -417,11 +421,16 @@ def _mutate_query_with_attributes_to_load(
417421 if attr not in _ATTRS_TO_CLEAN
418422 }
419423
424+ cond = or_ (
425+ func .lower (Attribute .name ).in_ (attrs ),
426+ func .lower (Attribute .name ) == "objectclass" ,
427+ )
428+
420429 return query .options (
421430 selectinload (qa (Directory .attributes )),
422431 with_loader_criteria (
423432 Attribute ,
424- func . lower ( Attribute . name ). in_ ( attrs ) ,
433+ cond ,
425434 ),
426435 )
427436
@@ -534,7 +543,7 @@ async def _fill_attrs(
534543 attrs : dict [str , list [str ]],
535544 session : AsyncSession ,
536545 ) -> None :
537- if "distinguishedname" not in self .requested_attrs or self .all_attrs :
546+ if "distinguishedname" in self .requested_attrs or self .all_attrs :
538547 attrs ["distinguishedName" ].append (distinguished_name )
539548
540549 if "whenCreated" in self .requested_attrs or self .all_attrs :
@@ -572,10 +581,6 @@ async def _fill_attrs(
572581 attrs ["memberOf" ].append (group .directory .path_dn )
573582
574583 if self .token_groups and "user" in obj_classes :
575- attrs ["tokenGroups" ].append (
576- str (string_to_sid (directory .object_sid )),
577- )
578-
579584 group_directories = await get_all_parent_group_directories (
580585 directory .groups ,
581586 session ,
@@ -584,7 +589,7 @@ async def _fill_attrs(
584589 if group_directories is not None :
585590 async for directory_ in group_directories :
586591 attrs ["tokenGroups" ].append (
587- str ( string_to_sid (directory_ .object_sid )),
592+ string_to_sid (directory_ .object_sid ), # type: ignore
588593 )
589594
590595 if self .member and "group" in obj_classes and directory .group :
@@ -638,6 +643,9 @@ async def tree_view( # noqa: C901
638643
639644 if attr .name .lower () == "objectclass" :
640645 obj_classes .append (value )
646+ if self .is_objectclass_requested :
647+ attrs [attr .name ].append (value )
648+ continue
641649
642650 attrs [attr .name ].append (value )
643651
0 commit comments