Skip to content

Commit 1f3ce1d

Browse files
bosdqwencoder
andcommitted
Add debug logging and error handling for missing field columns in relational import\n\n- Add debug logging to show available columns and field being searched for\n- Add error handling when field is not found in source DataFrame\n- Return appropriate error values when field is missing\n- Improve error messages to help diagnose column mapping issues\n\nThis will help diagnose why category_id import is failing by showing what columns\nare actually available in the source DataFrame.
Co-authored-by: Qwen-Coder <[email protected]>
1 parent 9a573d6 commit 1f3ce1d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/odoo_data_flow/lib/relational_import.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ def run_direct_relational_import(
190190
# 1. Prepare the owning model's IDs
191191
owning_df = pl.DataFrame({"external_id": id_map.keys(), "db_id": id_map.values()})
192192

193+
# Debug: Print available columns and the field we're looking for
194+
log.debug(f"Available columns in source_df: {source_df.columns}")
195+
log.debug(f"Looking for field: {field}")
196+
197+
# Check if the field exists in the DataFrame
198+
if field not in source_df.columns:
199+
log.error(f"Field '{field}' not found in source DataFrame. Available columns: {source_df.columns}")
200+
return None
201+
193202
# 2. Prepare the related model's IDs using the resolver
194203
all_related_ext_ids = source_df.get_column(field).str.split(",").explode()
195204
if related_model_fk is None:
@@ -254,6 +263,21 @@ def _prepare_link_dataframe(
254263
Returns:
255264
The prepared link DataFrame
256265
"""
266+
# Debug: Print available columns and the field we're looking for
267+
log.debug(f"Available columns in source_df: {source_df.columns}")
268+
log.debug(f"Looking for field: {field}")
269+
270+
# Check if the field exists in the DataFrame
271+
if field not in source_df.columns:
272+
log.error(f"Field '{field}' not found in source DataFrame. Available columns: {source_df.columns}")
273+
# Return an empty DataFrame with the expected schema
274+
return pl.DataFrame(schema={
275+
"external_id": pl.Utf8,
276+
field: pl.Utf8,
277+
owning_model_fk: pl.Int64,
278+
f"{related_model_fk}/id": pl.Int64
279+
})
280+
257281
# Create the link table DataFrame
258282
link_df = source_df.select(["id", field]).rename({"id": "external_id"})
259283
link_df = link_df.with_columns(pl.col(field).str.split(",")).explode(field)
@@ -313,6 +337,15 @@ def run_write_tuple_import(
313337
# 1. Prepare the owning model's IDs
314338
owning_df = pl.DataFrame({"external_id": id_map.keys(), "db_id": id_map.values()})
315339

340+
# Debug: Print available columns and the field we're looking for
341+
log.debug(f"Available columns in source_df: {source_df.columns}")
342+
log.debug(f"Looking for field: {field}")
343+
344+
# Check if the field exists in the DataFrame
345+
if field not in source_df.columns:
346+
log.error(f"Field '{field}' not found in source DataFrame. Available columns: {source_df.columns}")
347+
return False
348+
316349
# 2. Prepare the related model's IDs using the resolver
317350
all_related_ext_ids = source_df.get_column(field).str.split(",").explode()
318351
if related_model_fk is None:

0 commit comments

Comments
 (0)