Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lack of error passing for nested preload #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michalg9
Copy link

Make sure these boxes checked before submitting your pull request.

  • Do only one thing
  • No API-breaking changes
  • New code/logic commented & tested

For significant changes like big bug fixes, new features, please open an issue to make an agreement on an implementation design/plan first before starting it.

What did this pull request do?

For nested preloads there seems to be no passing of errors if a preload query fails. So for example in a test case from this PR, if Level2 preload fails with error for err = localDB.Preload("Level2").Find(&got).Error, then err != nil.

However, for nested preload fails this is not the case. If Level1 preload will fail with error from the DB, for the err = localDB.Preload("Level2.Level1").Find(&got).Error query we will have err == nil. This may lead to segmentation faults when objects that are expected to be preloaded (because err == nil) are in fact not preloaded and empty.

This PR fixes that by checking currentScope errors on preload callbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant