Skip to content

Commit 75e47fd

Browse files
committed
Fix 500 error
1 parent 7821e9f commit 75e47fd

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

CACHING_MIGRATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ curl -X POST "http://localhost:8000/cache/invalidate" \
158158
- [x] Replace in-memory caching in collection_apis.py
159159
- [x] Add cache management endpoints
160160
- [x] Update main app to include collection router
161+
- [x] Fix Pydantic v2 compatibility issues
161162
- [x] Document migration process
162163
- [ ] Deploy to staging environment
163164
- [ ] Verify Redis connectivity

opensensor/collection_apis.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,13 @@ def is_pydantic_model(obj):
207207
def get_nested_fields(model: Type[BaseModel]):
208208
nested_fields = {}
209209
for field_name, field in model.__fields__.items():
210-
if is_pydantic_model(field.type_):
211-
nested_fields[field_name] = field.type_
212-
elif get_origin(field.type_) is List and is_pydantic_model(get_args(field.type_)[0]):
213-
nested_fields[field_name] = get_args(field.type_)[0]
210+
# Handle both Pydantic v1 and v2 field access
211+
field_type = getattr(field, "type_", getattr(field, "annotation", None))
212+
213+
if is_pydantic_model(field_type):
214+
nested_fields[field_name] = field_type
215+
elif get_origin(field_type) is List and is_pydantic_model(get_args(field_type)[0]):
216+
nested_fields[field_name] = get_args(field_type)[0]
214217
return nested_fields
215218

216219

@@ -241,7 +244,10 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
241244
match_conditions[full_mongo_field_name] = {"$exists": True}
242245

243246
if field_name in nested_fields:
244-
if get_origin(field_type.type_) is List:
247+
# Handle both Pydantic v1 and v2 field access
248+
field_annotation = getattr(field_type, "type_", getattr(field_type, "annotation", None))
249+
250+
if get_origin(field_annotation) is List:
245251
nested_pipeline, nested_match = create_nested_pipeline(
246252
nested_fields[field_name], "" # Empty prefix for list items
247253
)

0 commit comments

Comments
 (0)