datetime_range throwing error in datetime_range_entity_view_display_presave()

Created on 1 November 2024, 3 months ago

Problem/Motivation

Encountering following error: Warning: Trying to access array offset on value of type null in datetime_range_entity_view_display_presave() (line 57 of core/modules/datetime_range/datetime_range.module).
This seems to happen because we use extra fields via ( extra_field_plus β†’ / Frontend Editing β†’ )

Extra fields don't seem to provide a field formatter - but the datetime_range code assumes that there's always one:

if (!in_array($plugin_definition['class'], $daterange_formatter_classes, FALSE)) {

According to \Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition() it is valid to return NULL, especially if $exception_on_invalid is set to FALSE - which our code does.

For 11.x this is obsolete due: 3442162 πŸ“Œ Remove redudundat hook_ENTITY_TYPE_presave() and ViewsConfigUpdater methods Active

Steps to reproduce

Proposed resolution

Add a check for $plugin_definition['class'].

Remaining tasks

  1. Writing code
  2. Reviews
  3. Merge

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

πŸ› Bug report
Status

Active

Version

10.5 ✨

Component

datetime.module

Created by

πŸ‡¨πŸ‡­Switzerland das-peter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @das-peter
  • πŸ‡¨πŸ‡­Switzerland das-peter
  • πŸ‡¨πŸ‡­Switzerland das-peter
  • Pipeline finished with Failed
    3 months ago
    Total: 615s
    #326649
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thanks for reporting

    Issue should be against 11.x as the current development branch

    Also as a bug will need test coverage.

    That said may need to do some backtracing to see why that value is empty vs just an isset check. To make sure we aren't masking a larger issue.

  • πŸ‡¨πŸ‡­Switzerland das-peter

    Thanks for the feedback.

    Issue should be against 11.x as the current development branch

    As written in the summary - For 11.x this is obsolete due: 3442162 πŸ“Œ Remove redudundat hook_ENTITY_TYPE_presave() and ViewsConfigUpdater methods Active
    There's no longer any similar code - at least not that I could find any.

    Also as a bug will need test coverage.

    Does it? Because the current behavior ignores/violates the contract set forth by the method called.
    As outlined in the summary:
    According to \Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition() it is valid to return NULL :

       * @return mixed
       *   A plugin definition, or NULL if the plugin ID is invalid and
       *   $exception_on_invalid is FALSE.
       *
       * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
       *   Thrown if $plugin_id is invalid and $exception_on_invalid is TRUE.
       */
      public function getDefinition($plugin_id, $exception_on_invalid = TRUE);
    

    I'm not sure if it really is necessary to have a test case for using the API not entirely correct.

    That said may need to do some backtracing to see why that value is empty vs just an isset check.

    I partially agree, at least on behalf of extra_field_plus β†’ / Frontend Editing β†’ but not from the perspective of the datetime_range module.
    The value gotten is NULL, which is a valid value for our purpose. If that wasn't meant to be NULL that's an issue for extra_field_plus β†’ / Frontend Editing β†’ .
    Or one could argue that there should be somewhere a warning triggered by some core component about that - but this isn't the scope of this issue. Happy to create a follow up issue if required.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Will leave in review but still believe needs a test case.

  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡¨πŸ‡­Switzerland das-peter

    Will leave in review but still believe needs a test case.

    Thanks for the feedback. I'll look into that. I suppose a simple UnitTest should do.

  • Pipeline finished with Failed
    3 months ago
    Total: 100s
    #328861
  • Pipeline finished with Failed
    3 months ago
    Total: 99s
    #328870
  • Pipeline finished with Failed
    3 months ago
    Total: 101s
    #328875
  • Pipeline finished with Success
    3 months ago
    Total: 509s
    #328878
  • πŸ‡¨πŸ‡­Switzerland das-peter

    Added unit test. Test only branch would fail. I guess testing pipeline will only work with MR's but I don't think I want to clutter MRs with test only. What's the best practice nowadays for test only changes to demonstrate bugfix & test coverage?

    Btw. that unit test setup doesn't seem cool.
    Happy to take pointers to enhance it...

  • Pipeline finished with Failed
    2 months ago
    Total: 480s
    #337238
  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    I'm also encountering this on a project (current latest 10 release). Diff did not apply to that tagged release so I could not test yet. If I find time I'll see if I can make a patch for 10.x

  • πŸ‡·πŸ‡ΊRussia zniki.ru

    Thanks for the MR, I left my feedback, please check. Set back to NW.

  • Issue was unassigned.
  • Status changed to Needs work 9 days ago
  • First commit to issue fork.
Production build 0.71.5 2024