Skip to content

Conversation

@bosd
Copy link
Member

@bosd bosd commented Sep 28, 2025

No description provided.

bosd added 2 commits September 27, 2025 23:22
…ng\n\n- Add detailed exception logging with full traceback for debugging batch load failures\n- Log complete exception information including type, message, and stack trace\n- Add comprehensive debugging for load response analysis and record creation verification\n- Log detailed information about what we get back from Odoo's model.load() call\n- Add enhanced error detection for load operation responses with proper message handling\n- Improve record creation count logging to show expected vs actual record creation\n- Add detailed warnings when record creation fails or is partial\n- Include sample data logging when no records are created to aid troubleshooting\n- Enhance exception handling to capture full failure information for debugging\n\nThis provides comprehensive debugging information to identify why records aren't being created\nand helps isolate issues in the batch load process, making it easier to troubleshoot\nrecord creation failures and XML ID resolution issues.
…ame 'sanitized_load_lines' is not defined in _execute_load_batch function\n- Correct variable scoping issues in batch load operations\n- Fix undefined variable references in debugging statements\n- Restore proper function implementation with correct variable names\n- Ensure batch load operations use correct variables throughout processing\n\nThis fixes the critical NameError that was preventing batch load operations from\ncompleting and causing record creation failures. The NameError was caused by\nreferencing undefined variables in the debugging and batch load code.\n\nThis resolves the core issue where batch load operations were failing due to\nundefined variable references, preventing successful record creation in Pass 1.
@gemini-code-assist
Copy link

Summary of Changes

Hello @bosd, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the robustness and debuggability of the Odoo data import process within the _execute_load_batch function. It introduces a critical step to sanitize id column values, mitigating potential XML ID constraint violations. Furthermore, it enhances the logging infrastructure to provide deeper insights into data transformations, Odoo API interactions, and exception details, which will aid in quicker identification and resolution of import issues.

Highlights

  • ID Sanitization: Implemented a new to_xmlid function to sanitize id column values, specifically the source_id, to prevent XML ID constraint violations when importing data into Odoo.
  • Enhanced Debugging and Logging: Added extensive debug logging throughout the _execute_load_batch function. This includes logging of sanitized IDs, a preview of sanitized data (with large fields truncated), and detailed information about the Odoo API response (type, keys, full content, and record counts).
  • Improved Exception Handling: Modified the exception handling to log the full traceback when an error occurs during batch loading, providing more comprehensive information for debugging.
  • Refactored Odoo Response Processing: Streamlined the logic for checking Odoo server messages and logging discrepancies between expected and created records, ensuring more precise error and warning reporting.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several enhancements to the batch loading process. It adds sanitization for ID columns to prevent XML ID violations and significantly improves debug logging by adding detailed information about the load response, sanitized data, and full tracebacks for exceptions. The changes are a good step towards more robust error handling and debugging. My review includes a few suggestions to improve code style, readability, and memory efficiency.

log.debug(f"Full first load_line: {load_lines[0]}")

# Sanitize the id column values to prevent XML ID constraint violations
from .lib.internal.tools import to_xmlid

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Per PEP 8, imports should be at the top of the file, not inside a function. This improves readability and makes dependencies clear. Please move from .lib.internal.tools import to_xmlid to the top-level imports of this module.

Comment on lines +706 to +724
sanitized_load_lines = []
for i, line in enumerate(load_lines):
sanitized_line = list(line)
if uid_index < len(sanitized_line):
# Sanitize the source_id (which is in the id column)
original_id = sanitized_line[uid_index]
sanitized_id = to_xmlid(original_id)
sanitized_line[uid_index] = sanitized_id
if i < 3: # Only log first 3 lines for debugging
log.debug(
f"Sanitized ID for line {i}: '{original_id}' -> '{sanitized_id}'"
)
else:
if i < 3: # Only log first 3 lines for debugging
log.warning(
f"Line {i} does not have enough columns for uid_index {uid_index}. "
f"Line has {len(line)} columns."
)
sanitized_load_lines.append(sanitized_line)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block creates a copy of load_lines to sanitize the ID column. For large batches, this can be memory-inefficient. Since load_lines is not used in its original form after this, you can modify it in-place to save memory. This also makes the code more concise. Assuming load_lines contains mutable lists, you can directly modify each line.

            for i, line in enumerate(load_lines):
                if uid_index < len(line):
                    # Sanitize the source_id (which is in the id column)
                    original_id = line[uid_index]
                    sanitized_id = to_xmlid(original_id)
                    line[uid_index] = sanitized_id
                    if i < 3:  # Only log first 3 lines for debugging
                        log.debug(
                            f"Sanitized ID for line {i}: '{original_id}' -> '{sanitized_id}'"
                        )
                else:
                    if i < 3:  # Only log first 3 lines for debugging
                        log.warning(
                            f"Line {i} does not have enough columns for uid_index {uid_index}. "
                            f"Line has {len(line)} columns."
                        )
            sanitized_load_lines = load_lines

# Log sample of sanitized data without large base64 content
log.debug(f"Load header: {load_header}")
log.debug(f"Load lines count: {len(sanitized_load_lines)}")
if sanitized_load_lines and len(sanitized_load_lines) > 0:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The condition if sanitized_load_lines and len(sanitized_load_lines) > 0: is redundant. In Python, a non-empty list evaluates to True in a boolean context, so if sanitized_load_lines: is sufficient and more idiomatic.

            if sanitized_load_lines:

if sanitized_load_lines and len(sanitized_load_lines) > 0:
# Show first line but truncate large base64 data
preview_line = []
for i, field_value in enumerate(sanitized_load_lines[0][:10] if len(sanitized_load_lines[0]) > 10 else sanitized_load_lines[0]):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The conditional expression to slice the first 10 fields is more complex than necessary. Slicing with [:10] already handles cases where the list has fewer than 10 elements gracefully by returning all available elements. You can simplify this.

                for i, field_value in enumerate(sanitized_load_lines[0][:10]):

error_str = str(e).lower()

# Log the full exception for debugging
import traceback

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While importing inside a function is sometimes acceptable for modules used only in exceptional paths, traceback is a standard library module and it's generally better practice to place all imports at the top of the file for clarity and consistency. This helps other developers quickly see all module dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants