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

APIv4 export action: find DAO by ID instead of just calling the constructor and setting the ID #24089

Merged
merged 1 commit into from
Jul 29, 2022

Conversation

jensschuppe
Copy link
Contributor

@jensschuppe jensschuppe commented Jul 29, 2022

Overview

Find DAO by ID instead of just calling the constructor and setting the ID. Otherwise, finding references might fail because of missing entity values when comparing, e.g. option_group_id for OptionVaue BAOs.

Before

Running e.g. OptionGroup.export might not work when finding references to option values, because comparing option_group_id will evaluate to null == null here:

if ($targetDao->option_group_id == $this->getTargetOptionGroupId()) {
return parent::findReferences($targetDao);
}

After

Comparison with BAO properties will be correct with the BAO being loaded via \CRM_Core_DAO::findById() instead of just calling the constructor and setting the BAO ID.

Technical Details

I'm not sure what might cause that null == null comparison in the first place, in my case it was comparing two unrelated option values that had both option_group_id not set.

…e ID

Otherwise, finding references might fail because of missing entity values when comparing, e.g. `option_group_id` for OptionVaue BAOs.
@civibot
Copy link

civibot bot commented Jul 29, 2022

(Standard links)

@colemanw
Copy link
Member

I think this is fine to merge as it looks more correct than what was there before, and there's decent test coverage.
Even better would be adding a test to cover the bug you experienced.

@seamuslee001 seamuslee001 merged commit 7e716de into civicrm:master Jul 29, 2022
@jensschuppe jensschuppe deleted the fix/Api4ExportActionDAO branch August 24, 2022 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants