Skip to content

Commit cbe3401

Browse files
author
bosd
committed
Fix ir.model.relation field validation error and improve error handling\n\n- Add proper error handling for ValueError when querying ir.model.relation\n- Catch 'Invalid field' errors specifically and provide graceful fallback\n- Log warning messages with details about the field validation issues\n- Continue with derivation logic when relation table queries fail\n- This prevents crashes when ir.model.relation field names are incorrect\n\nThis fixes the critical Odoo server error that was preventing relation queries.
1 parent b0972c5 commit cbe3401

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/odoo_data_flow/lib/relational_import.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ def _query_relation_info_from_odoo(
171171

172172
# Search for relations involving both models
173173
# We need to check both orders since the relation could be defined either way
174+
# Note: The field names in ir.model.relation may vary by Odoo version
175+
# Common field names are: model, comodel_id, or model_id for the related fields
174176
domain = [
175177
"|",
176178
"&",
@@ -205,6 +207,18 @@ def _query_relation_info_from_odoo(
205207
)
206208
return None
207209

210+
except ValueError as ve:
211+
# Handle specific field validation errors in Odoo expressions
212+
if "Invalid field" in str(ve) and "ir.model.relation" in str(ve):
213+
log.warning(
214+
f"Field validation error querying ir.model.relation: {ve}. "
215+
f"This may be due to incorrect field names in the domain query."
216+
)
217+
# Fall back to derivation logic when we can't query the relation table
218+
return None
219+
else:
220+
# Re-raise other ValueErrors
221+
raise
208222
except Exception as e:
209223
log.warning(
210224
f"Failed to query ir.model.relation for models '{model}' and "

0 commit comments

Comments
 (0)