Skip to content

datastore: fix WithIgnoreFieldMismatch for nested slices#13799

Merged
bhshkh merged 1 commit intogoogleapis:mainfrom
bhshkh:fix/ds-10822
Feb 6, 2026
Merged

datastore: fix WithIgnoreFieldMismatch for nested slices#13799
bhshkh merged 1 commit intogoogleapis:mainfrom
bhshkh:fix/ds-10822

Conversation

@bhshkh
Copy link
Copy Markdown
Contributor

@bhshkh bhshkh commented Feb 5, 2026

Fixes: #10822

This change ensures that propertyLoader.load continues iterating through slice elements even if individual elements encounter loading errors (like ErrFieldMismatch).

Previously, when loading a slice of structs, if one element caused an error (e.g. valid field mismatch), the loader would abort immediately. This prevented subsequent elements from being loaded, even if the user intended to ignore these mismatches using WithIgnoreFieldMismatch.

The fix captures the first error encountered but continues the loop to ensure all valid data is loaded. The error is returned at the end, preserving the existing error reporting behavior (which WithIgnoreFieldMismatch relies on).

@bhshkh bhshkh requested review from a team February 5, 2026 19:07
@bhshkh bhshkh requested review from a team as code owners February 5, 2026 19:07
@product-auto-label product-auto-label Bot added the api: datastore Issues related to the Datastore API. label Feb 5, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @bhshkh, 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 refines the data loading mechanism for slices within the datastore, ensuring that the WithIgnoreFieldMismatch option behaves correctly. By modifying the error handling logic, the system now processes all slice elements, capturing only the initial error, which allows for more robust and complete data loading when partial failures are expected or ignored.

Highlights

  • Error Handling in Slice Loading: The load function in datastore/load.go has been modified to continue processing all elements of a slice even if an error occurs during the loading of an individual element. Previously, the function would abort immediately upon the first error.
  • Preserving First Error: While iterating through slice elements, the first error encountered is now captured and stored. The function will return this first error only after attempting to load all elements in the slice.
  • Fix for WithIgnoreFieldMismatch: This change specifically addresses an issue where the WithIgnoreFieldMismatch option was not functioning as intended for nested slices, as the loader would stop prematurely on the first field mismatch error.
Changelog
  • datastore/load.go
    • Modified the load method to iterate through all slice elements, even if loadOneElement returns an error for a specific element.
    • Introduced a firstErr variable to store the initial error encountered during slice iteration, returning it only after the loop completes.
Activity
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
Copy Markdown
Contributor

@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 addresses a bug where loading data into a slice of structs would prematurely terminate upon encountering an error, such as a field mismatch, even when WithIgnoreFieldMismatch was specified. The change modifies the property loader to continue iterating through all slice elements, capturing the first error but ensuring all valid data is loaded. This aligns with the expected behavior of WithIgnoreFieldMismatch. The fix is well-targeted and correctly implemented. I have no further suggestions.

Comment thread datastore/load.go
if !ok {
return l.loadOneElement(codec, structValue, p, prev)
}
var firstErr string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks odd to me because you're propagating strings rather than errors, but it adheres to the loadOneElement contract.

@bhshkh bhshkh merged commit 0e4e7ec into googleapis:main Feb 6, 2026
10 checks passed
@bhshkh bhshkh deleted the fix/ds-10822 branch February 6, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: datastore Issues related to the Datastore API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

datastore: WithIgnoreFieldMismatch option works for just first record in embedded / nested struct array case.

2 participants