aiteamutils 0.2.130__py3-none-any.whl → 0.2.132__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aiteamutils/database.py CHANGED
@@ -7,11 +7,12 @@ from typing import (
7
7
  Dict,
8
8
  List,
9
9
  Optional,
10
- AsyncGenerator
10
+ AsyncGenerator,
11
+ Union
11
12
  )
12
13
  from sqlalchemy.ext.asyncio import AsyncSession
13
14
  from sqlalchemy import select, and_, or_
14
- from sqlalchemy.orm import DeclarativeBase, joinedload, selectinload
15
+ from sqlalchemy.orm import DeclarativeBase, joinedload, selectinload, contains_eager
15
16
  from sqlalchemy.exc import SQLAlchemyError
16
17
  from datetime import datetime
17
18
  from contextlib import asynccontextmanager
@@ -151,21 +152,36 @@ def process_response(
151
152
  if not entity:
152
153
  return None
153
154
 
155
+ print(f"\n[DEBUG] Processing entity: {entity.__class__.__name__}")
156
+ print(f"[DEBUG] Entity dict: {entity.__dict__}")
157
+
154
158
  # 모든 필드 처리
155
159
  result = process_columns(entity)
160
+ print(f"[DEBUG] After process_columns: {result}")
156
161
 
157
162
  # Relationship 처리 (이미 로드된 관계만 처리)
158
163
  for relationship in entity.__mapper__.relationships:
164
+ print(f"\n[DEBUG] Processing relationship: {relationship.key}")
159
165
  if not relationship.key in entity.__dict__:
166
+ print(f"[DEBUG] Relationship {relationship.key} not in entity.__dict__")
160
167
  continue
161
168
 
162
169
  try:
163
170
  value = getattr(entity, relationship.key)
171
+ print(f"[DEBUG] Relationship value: {value}")
172
+
164
173
  # response_model이 있는 경우 해당 필드의 annotation type을 가져옴
165
174
  nested_response_model = None
166
175
  if response_model and relationship.key in response_model.model_fields:
167
176
  field_info = response_model.model_fields[relationship.key]
168
177
  nested_response_model = field_info.annotation
178
+ print(f"[DEBUG] Found nested response model for {relationship.key}: {nested_response_model}")
179
+
180
+ # Optional[ProjectResponse] 같은 경우 실제 모델 추출
181
+ if hasattr(nested_response_model, '__origin__') and nested_response_model.__origin__ is Union:
182
+ print(f"[DEBUG] Extracting actual model from Union type: {nested_response_model.__args__}")
183
+ nested_response_model = next((t for t in nested_response_model.__args__ if hasattr(t, 'model_fields')), None)
184
+ print(f"[DEBUG] Extracted model: {nested_response_model}")
169
185
 
170
186
  if value is not None:
171
187
  if isinstance(value, list):
@@ -174,23 +190,39 @@ def process_response(
174
190
  for item in value
175
191
  ]
176
192
  else:
193
+ print(f"[DEBUG] Processing single value with model: {nested_response_model}")
177
194
  result[relationship.key] = process_response(value, nested_response_model)
195
+ print(f"[DEBUG] After processing relationship {relationship.key}: {result[relationship.key]}")
178
196
  else:
179
197
  result[relationship.key] = None
180
- except Exception:
198
+ except Exception as e:
199
+ print(f"[DEBUG] Error processing relationship {relationship.key}: {str(e)}")
200
+ import traceback
201
+ print(f"[DEBUG] Full traceback: {traceback.format_exc()}")
181
202
  result[relationship.key] = None
182
203
 
204
+ print(f"\n[DEBUG] Before response model processing: {result}")
183
205
  # response_model이 있는 경우 필터링
184
206
  if response_model:
207
+ print(f"[DEBUG] Response model fields: {response_model.model_fields}")
185
208
  # 현재 키 목록을 저장
186
209
  current_keys = list(result.keys())
187
210
  # response_model에 없는 키 제거
188
211
  for key in current_keys:
189
212
  if key not in response_model.model_fields:
213
+ print(f"[DEBUG] Removing key not in response model: {key}")
190
214
  result.pop(key)
191
215
  # 모델 검증 및 업데이트
192
- result.update(response_model(**result).model_dump())
216
+ try:
217
+ validated_result = response_model(**result).model_dump()
218
+ print(f"[DEBUG] After validation: {validated_result}")
219
+ result.update(validated_result)
220
+ except Exception as e:
221
+ print(f"[DEBUG] Error during validation: {str(e)}")
222
+ import traceback
223
+ print(f"[DEBUG] Full validation traceback: {traceback.format_exc()}")
193
224
 
225
+ print(f"[DEBUG] Final result: {result}")
194
226
  return result
195
227
 
196
228
  ##################
@@ -448,17 +480,17 @@ async def list_entities(
448
480
  List[Dict[str, Any]]: 쿼리 결과 리스트.
449
481
  """
450
482
  try:
451
- # 명시적 조인이 있는 경우
483
+ query = select(model)
484
+
485
+ # 명시적 조인 적용
452
486
  if explicit_joins:
453
- query = select(model, *explicit_joins)
454
487
  for join_target in explicit_joins:
455
488
  query = query.outerjoin(join_target)
456
- # 명시적 조인이 없는 경우
457
- else:
458
- query = select(model)
459
- if loading_joins:
460
- for join_option in loading_joins:
461
- query = query.options(join_option)
489
+
490
+ # 조인 로딩 적용
491
+ if loading_joins:
492
+ for join_option in loading_joins:
493
+ query = query.options(join_option)
462
494
 
463
495
  # 필터 조건 적용
464
496
  if filters:
@@ -485,8 +517,7 @@ async def list_entities(
485
517
  query = query.limit(limit).offset(skip)
486
518
 
487
519
  result = await session.execute(query)
488
-
489
- return result.scalars().unique().all()
520
+ return result.unique().scalars().all()
490
521
  except SQLAlchemyError as e:
491
522
  raise CustomException(
492
523
  ErrorCode.DB_READ_ERROR,
@@ -503,17 +534,17 @@ async def get_entity(
503
534
  loading_joins: Optional[List[Any]] = None
504
535
  ) -> ModelType:
505
536
  try:
506
- # 명시적 조인이 있는 경우
537
+ query = select(model)
538
+
539
+ # 명시적 조인 적용
507
540
  if explicit_joins:
508
- query = select(model, *explicit_joins)
509
541
  for join_target in explicit_joins:
510
542
  query = query.outerjoin(join_target)
511
- # 명시적 조인이 없는 경우
512
- else:
513
- query = select(model)
514
- if loading_joins:
515
- for join_option in loading_joins:
516
- query = query.options(join_option)
543
+
544
+ # 조인 로딩 적용
545
+ if loading_joins:
546
+ for join_option in loading_joins:
547
+ query = query.options(join_option)
517
548
 
518
549
  if conditions:
519
550
  for key, value in conditions.items():
aiteamutils/version.py CHANGED
@@ -1,2 +1,2 @@
1
1
  """버전 정보"""
2
- __version__ = "0.2.130"
2
+ __version__ = "0.2.132"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aiteamutils
3
- Version: 0.2.130
3
+ Version: 0.2.132
4
4
  Summary: AI Team Utilities
5
5
  Project-URL: Homepage, https://github.com/yourusername/aiteamutils
6
6
  Project-URL: Issues, https://github.com/yourusername/aiteamutils/issues
@@ -4,12 +4,12 @@ aiteamutils/base_repository.py,sha256=vzBw3g3jCJetTDblZvZenEGXk89Qu_65_02C7QTcf8
4
4
  aiteamutils/base_service.py,sha256=nHikjwGp29QrQPr2W8Ye9sKxmVS_8prRG3Nu42TU1Ms,10670
5
5
  aiteamutils/cache.py,sha256=07xBGlgAwOTAdY5mnMOQJ5EBxVwe8glVD7DkGEkxCtw,1373
6
6
  aiteamutils/config.py,sha256=YdalpJb70-txhGJAS4aaKglEZAFVWgfzw5BXSWpkUz4,3232
7
- aiteamutils/database.py,sha256=9E5vFC22qeAhU-M4bfzNO53rg43y3CSAsSqrwHmEOHI,20175
7
+ aiteamutils/database.py,sha256=XwgienPxjGr-PXdfYg6RDOLinNywNk1enYWegB-86uQ,22042
8
8
  aiteamutils/enums.py,sha256=7WLqlcJqQWtETAga2WAxNp3dJTQIAd2TW-4WzkoHHa8,2498
9
9
  aiteamutils/exceptions.py,sha256=pgf3ersezObyl17wAO3I2fb8m9t2OzWDX1mSjwAWm2Y,16035
10
10
  aiteamutils/security.py,sha256=McUl3t5Z5SyUDVUHymHdDkYyF4YSeg4g9fFMML4W6Kw,11630
11
11
  aiteamutils/validators.py,sha256=msOrha36xWsapm4VAh63YmFq1GVyC9tzZcjXYFCEZ_g,11949
12
- aiteamutils/version.py,sha256=5aeO7zjAJZOoyv7QoPV87xtSy3aI2ZThWMEkD64jV1k,43
13
- aiteamutils-0.2.130.dist-info/METADATA,sha256=xNXV2bfD3s3Q60uE1K3G5KZAMKNq11enqX-OIbFHBk8,1719
14
- aiteamutils-0.2.130.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
- aiteamutils-0.2.130.dist-info/RECORD,,
12
+ aiteamutils/version.py,sha256=j19bkYR2Nt5EhQU7qr9qZbsT-v5l9WzURNYBBdlPff8,43
13
+ aiteamutils-0.2.132.dist-info/METADATA,sha256=R7s9jHRbAWS6PJXas8sWCOuUGIqIXIpjLhe5QEOpE7s,1719
14
+ aiteamutils-0.2.132.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
+ aiteamutils-0.2.132.dist-info/RECORD,,