Skip to content

Throw exception when baoName is not found #20696

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

Merged
merged 1 commit into from
Jun 25, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

Throw exception when baoName is not found in v4 api get requests

Before

If a race condition arises where the entity is called before it is registered a fatal error results

After

In same situation an exception is thrown.

Technical Details

An exception is more recoverable than a fatal error.

The specific case I'm hitting at the moment relates to monolog - the
caching of the symfony container means it persists between builds and is
accessed before the extension is installed. However the entity is not
yet registered via entityTypes hook. Interestingly my call to apiv4.getEntities
does find it to be available.

Historically I have hit this fatal in other scenarios but I can't recall the details.

Comments

@civibot
Copy link

civibot bot commented Jun 23, 2021

(Standard links)

public function _run(Result $result) {
// Early return if table doesn't exist yet due to pending upgrade
$baoName = $this->getBaoName();
if (!$baoName) {
// In some cases (eg. site spin-up) the code may attempt to call the api before the entity name is registered.
throw new \API_Exception("BAO for {$this->getEntityName()}is not available. This could be a load-order issue");
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a space after the entity name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@seamuslee001
Copy link
Contributor

This can be merged when @colemanw 's comment / issue is resolved

It the BAO name is not found at this point we currently get a fatal error. This makes it more
recoverable. The specific case I'm hitting at the moment relates to monolog - the
caching of the symfony container means it persists between builds and is
accessed before the extension is installed. However the entity is not
yet registered. Historically I have hit this fatal in other
scenarios but I can't recall the details.
@MegaphoneJon
Copy link
Contributor

This is a valuable step forward - issues relating to CachedCiviContainer.x and extensions not being registered at the time they're accessed has been by far the biggest source of instability in CiviCRM for me in recent months.

The mechanisms are outside my current understanding but am happy to test future PRs now that we've started to isolate the issue.

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.

4 participants