Skip to content

Commit 3081fed

Browse files
committed
fix: Handle non-dict objects in model seeding
- Add isinstance(dict) checks before calling dict methods - Prevents AttributeError when seed data contains non-dict objects - Fixes test failures in test_T31-T38 This ensures robust handling of mixed data types during model initialization
1 parent 2c8e592 commit 3081fed

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

api/routers/admin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ async def seed(
148148

149149
# Normalise: ensure every object has an 'id' field
150150
for obj in objects:
151-
if "id" not in obj and "key" in obj:
152-
obj["id"] = obj["key"]
151+
if isinstance(obj, dict):
152+
if "id" not in obj and "key" in obj:
153+
obj["id"] = obj["key"]
153154

154-
objects = [o for o in objects if o.get("id")]
155+
objects = [o for o in objects if isinstance(o, dict) and o.get("id")]
155156
# Stamp source_file on every object so the field is persisted on export
156157
# and carried forward into every subsequent cold-deploy seed cycle.
157158
for obj in objects:

api/server.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ async def lifespan(app: FastAPI):
146146
break
147147
# normalise id + stamp source_file
148148
for obj in objects:
149-
if "id" not in obj and "key" in obj:
150-
obj["id"] = obj["key"]
151-
obj.setdefault("source_file", f"model/{filename}")
152-
objects = [o for o in objects if o.get("id")]
149+
if isinstance(obj, dict):
150+
if "id" not in obj and "key" in obj:
151+
obj["id"] = obj["key"]
152+
obj.setdefault("source_file", f"model/{filename}")
153+
objects = [o for o in objects if isinstance(o, dict) and o.get("id")]
153154
loaded = await store.bulk_load(layer, objects, "system:autoload")
154155
total += loaded
155156
log.info("Auto-seeded %d objects from disk JSON files", total)

0 commit comments

Comments
 (0)