- Issue created by @carolpettirossi
- 🇨🇦Canada endless_wander
I am experiencing this error when registering for an event instance:
Error: Call to a member function getCacheTagsToInvalidate() on null in Drupal\recurring_events_registration\Entity\Registrant->getCacheTagsToInvalidate() (line 397 of modules/contrib/recurring_events/modules/recurring_events_registration/src/Entity/Registrant.php).
This line refers to:
$this->getEventInstance()->getCacheTagsToInvalidate(),
The event instance is not being found. Checking
getEventInstance()
and see it is justreturn $this->get('eventinstance_id')->entity;
which means that the eventinstance_id must not be getting set for the registrant. - 🇨🇦Canada endless_wander
This error does not happen without custom Guests submodule enabled so I believe this is related to https://www.drupal.org/project/recurring_events/issues/3257502#comment-1... ✨ Allow registrations to be for multiple people -- e.g., adding guests or "plus one" Needs review which was caused by the registration creation service no longer sharing the event details by default -- https://www.drupal.org/project/recurring_events/issues/3452632 🐛 Registration creation service leaks data Fixed
- 🇨🇦Canada endless_wander
Inside Registrant::getCacheTagsToInvalidate(),
$this->getEventInstance()
is always returning NULL for me.getCacheTagsToInvalidate() is called via invalidateTagsOnSave(), which happens in entity's postSave() method. During postSave() I can see
$this->getEventInstance()
does return the expected value.At some point EntityBase::getCacheTags() is called, which also calls getCacheTagsToInvalidate(). If getCacheTags() is commented out, the error is no longer triggered. This seems to be the problem point.
If I provide the eventinstance and eventseries directly to either getCacheTags() or getCacheTagsToInvalidate(), then the error is not triggered. For now, this patch stops the error from occurring, but this seems like a weird, unnecessary fix and badly coded so this is just a stopgap solution for me to keep working.
- 🇧🇬Bulgaria pfrenssen Sofia
I am seeing this error as well, in my case I somehow have an orphaned registrant that is referencing an event instance that no longer exists. I also see other errors in my logs relating to the same issue. Everywhere we are calling
::getEventInstance()
we are assuming that we will always get an event instance object back, but this is not guaranteed:- On a newly created
Registrant
entity the event instance might not yet have been set. This is possibly what is causing the problem reported by - The field
eventinstance_id
is not set as a required field, so it is possible to save registrants without referencing an event instance.
I think the best solution is probably to change the documentation of the method to reflect the fact that it can return
NULL
and fix all calling code to check the value. - On a newly created
- Assigned to pfrenssen
- 🇧🇬Bulgaria pfrenssen Sofia
Picking this up. Promoting to major since it is blocking registrations.
- 🇨🇦Canada endless_wander
@pfrenssen is the bug caused by change in https://www.drupal.org/project/recurring_events/issues/3452632 🐛 Registration creation service leaks data Fixed do you think?
- 🇧🇬Bulgaria pfrenssen Sofia
@pfrenssen is the bug caused by change in https://www.drupal.org/project/recurring_events/issues/3452632 🐛 Registration creation service leaks data Fixed do you think?
No it is caused by 🐛 Make sure event instances are invalidated when registrants change Fixed . The method
::getCacheTagsToInvalidate()
was assuming that there is always an event instance referenced (as was implied by the method signature), but this is not the case. We should just check that it exists before calling methods on it. - 🇧🇬Bulgaria pfrenssen Sofia
Started an MR with a test that shows the bug (ref. https://git.drupalcode.org/issue/recurring_events-3462480/-/jobs/2277646)
1) Drupal\Tests\recurring_events_registration\Kernel\RegistrantTest::testGetCacheTagsToInvalidate with data set "newly created, unsaved registrant" (false, false, false) Error: Call to a member function getCacheTagsToInvalidate() on null
Now let's fix it. I will do the following:
- Fix the bug in
::getCacheTagsToInvalidate()
. - Update the documentation and method signature of
::getEventInstance()
so that it is clear in the future that this potentially returnsNULL
. - I will do the same for
::getEventSeries()
which also potentially returnsNULL
. - Go through the code and fix cases where the calling code should check if the return value is
NULL
before calling methods on it.
- Fix the bug in
- Issue was unassigned.
- Status changed to Needs review
9 months ago 3:08pm 30 July 2024 - Merge request !103Change the documentation and method signature of the event reference getters. → (Open) created by pfrenssen
- Assigned to pfrenssen
- Status changed to Needs work
8 months ago 4:08pm 30 July 2024 - 🇧🇬Bulgaria pfrenssen Sofia
I am testing in my project. I am seeing another error with an orphaned event registration:
Error: Call to a member function id() on null in recurring_events_registration_entity_operation() (line 440 of modules/contrib/recurring_events/modules/recurring_events_registration/recurring_events_registration.module).
- Issue was unassigned.
- Status changed to Needs review
8 months ago 5:30pm 30 July 2024 -
pfrenssen →
committed 3f0edec2 on 2.0.x
Issue #3462480 by pfrenssen, chrisla, carolpettirossi: Error when...
-
pfrenssen →
committed 3f0edec2 on 2.0.x
-
pfrenssen →
committed 3f0edec2 on 3.0.x
Issue #3462480 by pfrenssen, chrisla, carolpettirossi: Error when...
-
pfrenssen →
committed 3f0edec2 on 3.0.x
Automatically closed - issue fixed for 2 weeks with no activity.
- Status changed to Fixed
3 months ago 9:30am 3 January 2025 - 🇨🇦Canada endless_wander
I have tested against 2.0.2 version of module and found this solved this bug of upgrading.
I would suggest future fixes like this are tested and merged into both branches perhaps, rather than just release for the 3.0 version that won't be released for a while. Could this be merged into 2.0 branch as well so a patch is not required?