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

dev/core#3056 - Crash with search builder if civigrant not enabled and have admin rights #22714

Merged
merged 1 commit into from
Feb 9, 2022

Conversation

demeritcowboy
Copy link
Contributor

@demeritcowboy demeritcowboy commented Feb 6, 2022

Overview

https://lab.civicrm.org/dev/core/-/issues/3056

Search Builder, as in Search -> Search Builder (civicrm/contact/search/builder), crashes if CiviGrant not enabled and you are an admin or have access CiviGrant permission still.

Before

  1. Disable the CiviGrant extension if not already disabled.
  2. Log in as e.g. drupal user 1
  3. Go to search builder, or try to edit the criteria you have for an existing smart group based on search builder.
  4. Error: Class 'CRM_Grant_BAO_Grant' not found in CRM_Core_BAO_Mapping::addComponentFields() (line 764 of ...\CRM\Core\BAO\Mapping.php).

After

Ok

Technical Details

CiviGrant was moved to an extension in 5.47. Search builder still references it.

Comments

It looks like 5.47 hasn't branched yet so putting against master. I'll rebase if it branches first.

@civibot
Copy link

civibot bot commented Feb 6, 2022

(Standard links)

@colemanw
Copy link
Member

colemanw commented Feb 6, 2022

Nice job with the test @demeritcowboy!

@totten totten changed the base branch from master to 5.47 February 6, 2022 04:34
@civibot civibot bot added 5.47 and removed master labels Feb 6, 2022
@totten
Copy link
Member

totten commented Feb 6, 2022

Test failure from first run looks related.

It looks like 5.47 hasn't branched yet so putting against master. I'll rebase if it branches first.

Cool. In this case, I think we can just edit the PR header. (The current base-commit is a common ancestor.)

@seamuslee001
Copy link
Contributor

@demeritcowboy still the same test failure as before

@demeritcowboy
Copy link
Contributor Author

Yes but the versioncheck test that's failing is pointing to maybe a larger issue with civigrant so want to sort that out first. See https://lab.civicrm.org/dev/core/-/issues/3057. It should have been failing for the last month, and should be also failing in master. I am perplexed.

@demeritcowboy demeritcowboy changed the title dev/core#3506 - Crash with search builder if civigrant not enabled and have admin rights dev/core#3056 - Crash with search builder if civigrant not enabled and have admin rights Feb 7, 2022
@demeritcowboy
Copy link
Contributor Author

I don't know what's different about the test node that's making it think search builder is a custom search. When I put in some debugging, on my local the "selector name" below is just CRM_Contact_Selector. What makes it be "custom" here?

CRM_Core_InvokeTest::testOpeningSearchBuilder
Exception: selector name: CRM_Contact_Selector_Custom
customsearchclass: 

/home/jenkins/bknix-dfl/build/core-22714-6qvcz/web/sites/all/modules/civicrm/CRM/Contact/Form/Search.php:697
/home/jenkins/bknix-dfl/build/core-22714-6qvcz/web/sites/all/modules/civicrm/CRM/Contact/Form/Search/Builder.php:47
/home/jenkins/bknix-dfl/build/core-22714-6qvcz/web/sites/all/modules/civicrm/CRM/Core/Form.php:668
/home/jenkins/bknix-dfl/build/core-22714-6qvcz/web/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Display.php:76
/home/jenkins/bknix-dfl/build/core-22714-6qvcz/web/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php:203
/home/jenkins/bknix-dfl/build/core-22714-6qvcz/web/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php:103
/home/jenkins/bknix-dfl/build/core-22714-6qvcz/web/sites/all/modules/civicrm/CRM/Core/Controller.php:355
/home/jenkins/bknix-dfl/build/core-22714-6qvcz/web/sites/all/modules/civicrm/CRM/Core/Invoke.php:319
/home/jenkins/bknix-dfl/build/core-22714-6qvcz/web/sites/all/modules/civicrm/tests/phpunit/CRM/Core/InvokeTest.php:60

@totten
Copy link
Member

totten commented Feb 9, 2022

There is a spooky interaction between CRM_Core_FormTest and the new CRM_Core_InvokeTest. You get the error when running them together:

$ env PHPUNIT_TESTS='CRM_Core_FormTest CRM_Core_InvokeTest' CIVICRM_UF=UnitTests phpunit8 tests/phpunit/EnvTests.php --stop-on-failure --debug

Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (through xdebug.client_host/xdebug.client_port) :-(
Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (through xdebug.client_host/xdebug.client_port) :-(
Parsing schema description /Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/xml/schema/Schema.xml
Extracting database information
Extracting table information
PHPUnit 8.5.15 by Sebastian Bergmann and contributors.

Test 'CRM_Core_FormTest::testOpeningForms with data set "Add New Tag" ('civicrm/tag/edit?action=add&parent_id=')' started
Test 'CRM_Core_FormTest::testOpeningForms with data set "Add New Tag" ('civicrm/tag/edit?action=add&parent_id=')' ended

Installing tmptest_aqpy6 database
Test 'CRM_Core_FormTest::testOpeningForms with data set "Location Type" ('civicrm/admin/locationType?reset=1')' started
Test 'CRM_Core_FormTest::testOpeningForms with data set "Location Type" ('civicrm/admin/locationType?reset=1')' ended
Test 'CRM_Core_FormTest::testOpeningForms with data set "Assign Account to Financial Type" ('civicrm/admin/financial/finan...&aid=1')' started
Test 'CRM_Core_FormTest::testOpeningForms with data set "Assign Account to Financial Type" ('civicrm/admin/financial/finan...&aid=1')' ended
Test 'CRM_Core_FormTest::testOpeningForms with data set "Find Contacts" ('civicrm/contact/search?reset=1')' started
Test 'CRM_Core_FormTest::testOpeningForms with data set "Find Contacts" ('civicrm/contact/search?reset=1')' ended
Test 'CRM_Core_FormTest::testOpeningForms with data set "Fulltext search" ('civicrm/contact/search/custom...eset=1')' started
Test 'CRM_Core_FormTest::testOpeningForms with data set "Fulltext search" ('civicrm/contact/search/custom...eset=1')' ended
Test 'CRM_Core_FormTest::testOpeningForms with data set "New Email" ('civicrm/activity/email/add?at...dalone')' started
Test 'CRM_Core_FormTest::testOpeningForms with data set "New Email" ('civicrm/activity/email/add?at...dalone')' ended
Test 'CRM_Core_FormTest::testOpeningForms with data set "Message Templates" ('civicrm/admin/messageTemplates?reset=1')' started
Test 'CRM_Core_FormTest::testOpeningForms with data set "Message Templates" ('civicrm/admin/messageTemplates?reset=1')' ended
Test 'CRM_Core_FormTest::testOpeningForms with data set "Scheduled Jobs" ('civicrm/admin/job?reset=1')' started
Test 'CRM_Core_FormTest::testOpeningForms with data set "Scheduled Jobs" ('civicrm/admin/job?reset=1')' ended
Test 'CRM_Core_FormTest::testNewPriceField' started
Test 'CRM_Core_FormTest::testNewPriceField' ended
Test 'CRM_Core_InvokeTest::testInvokeDashboardForNonAdmin' started
Test 'CRM_Core_InvokeTest::testInvokeDashboardForNonAdmin' ended
Test 'CRM_Core_InvokeTest::testInvokeDashboardWithGettingStartedDashlet' started
Test 'CRM_Core_InvokeTest::testInvokeDashboardWithGettingStartedDashlet' ended
Test 'CRM_Core_InvokeTest::testOpeningSearchBuilder' started

Warning: Uncaught require_once(.php): failed to open stream: No such file or directory

/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Contact/Selector/Custom.php:126
/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Contact/Selector/Custom.php:126
/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Contact/Form/Search.php:702
/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Contact/Form/Search/Builder.php:47
/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Core/Form.php:668
/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Display.php:76
/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php:203
/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php:103
/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Core/Controller.php:355
/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Core/Invoke.php:319
/Users/ in /Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Contact/Selector/Custom.php on line 126

Fatal error: CRM_Contact_Selector_Custom::__construct(): Failed opening required '.php' (include_path='/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/ext/flexmailer/:/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/ext/legacycustomsearches/:/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/ext/ckeditor4/:/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/ext/recaptcha/:/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/ext/financialacls/:/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/ext/eventcart/:/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/ext/greenwich/:.:/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm:/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/packages:/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/vendor/tecnickcom:/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/vendor/pear/pear_exception:/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/vendor/pear/auth_sasl:/Users/totten/b in /Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Contact/Selector/Custom.php on line 126

And then running the new test by itself, it passes:

env PHPUNIT_TESTS='CRM_Core_InvokeTest' CIVICRM_UF=UnitTests phpunit8 tests/phpunit/EnvTests.php --stop-on-failure --debug
Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (through xdebug.client_host/xdebug.client_port) :-(
Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (through xdebug.client_host/xdebug.client_port) :-(
Parsing schema description /Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/xml/schema/Schema.xml
Extracting database information
Extracting table information
PHPUnit 8.5.15 by Sebastian Bergmann and contributors.

Test 'CRM_Core_InvokeTest::testInvokeDashboardForNonAdmin' started
Test 'CRM_Core_InvokeTest::testInvokeDashboardForNonAdmin' ended

Installing tmptest_aqpy6 database
Test 'CRM_Core_InvokeTest::testInvokeDashboardWithGettingStartedDashlet' started
Test 'CRM_Core_InvokeTest::testInvokeDashboardWithGettingStartedDashlet' ended
Test 'CRM_Core_InvokeTest::testOpeningSearchBuilder' started
Test 'CRM_Core_InvokeTest::testOpeningSearchBuilder' ended


Time: 4.01 seconds, Memory: 76.50 MB

OK (3 tests, 33 assertions)

@totten
Copy link
Member

totten commented Feb 9, 2022

Specifically, the interaction arises with testOpeningForms(...Fulltext search...):


PHPUnit 8.5.15 by Sebastian Bergmann and contributors.

Test 'CRM_Core_FormTest::testOpeningForms with data set "Fulltext search" ('civicrm/contact/search/custom...eset=1')' started
Test 'CRM_Core_FormTest::testOpeningForms with data set "Fulltext search" ('civicrm/contact/search/custom...eset=1')' ended

Installing tmptest_aqpy6 database
Test 'CRM_Core_InvokeTest::testOpeningSearchBuilder' started

Warning: Uncaught require_once(.php): failed to open stream: No such file or directory

/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Contact/Selector/Custom.php:126
/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Contact/Selector/Custom.php:126
/Users/totten/bknix/build/tmp/web/sites/all/modules/civicrm/CRM/Contact/Form/Search.php:702```

@totten
Copy link
Member

totten commented Feb 9, 2022

I believe the leak is in CRM_Contact_Form_Search::$_selectorName. Adding this to CRM_Core_FormTest appears to fix the interaction:

  protected function tearDown(): void {
    parent::tearDown();
    CRM_Contact_Form_Search::$_selectorName = 'CRM_Contact_Selector';
  }

But surely that cleanup belongs somewhere else...

@demeritcowboy
Copy link
Contributor Author

Ahh nice. Thanks for tracking down the spooky action. So we've invented quantum entangled tests then.

Will take a look - those FormTest ones were an earlier attempt and they do have some flaws so what I might do is convert them to Invoke, but will look at the fulltext one.

@demeritcowboy
Copy link
Contributor Author

Just seeing what this breaks now.

@demeritcowboy
Copy link
Contributor Author

Jenkins retest this please.

I've clicked around and checked universe and I think this might be the way to handle $_selectorName. It might be even better to make it non-static but then there's also the static functions where it gets used and I didn't want to go that far.

@seamuslee001
Copy link
Contributor

The final patch seems fine to me and I note tests have passed now. so I think this should be ok to merge right @demeritcowboy ?

@demeritcowboy
Copy link
Contributor Author

I added the constructor part, but otherwise it's the same as earlier. So it's just if someone sees an issue with the added constructor, which just repeats the assignment from the property declaration a few lines up.

@colemanw colemanw merged commit 75ae69d into civicrm:5.47 Feb 9, 2022
@demeritcowboy
Copy link
Contributor Author

Thanks all!

@demeritcowboy demeritcowboy deleted the grant-searchbuilder branch February 9, 2022 23:19
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