Ajax error on [Add exception] button if "seasons" is activated

Created on 3 November 2023, about 1 year ago
Updated 1 December 2023, about 1 year ago

Hi,
if both "seasons" and "exception days" are activated I can't add a new exception day on a Node form. The following error occurs when the button [Add exception] is clicked upon:

Console says:


Uncaught 
Object { message: "\nEin AJAX-HTTP-Fehler ist aufgetreten.\nHTTP-RΓΌckgabe-Code: 500\nDebugging information follows.\nPath: /node/14/edit?ajax_form=1\nStatustext: error\nAntworttext: Auf der Website ist ein unvorhergesehener Fehler aufgetreten. Bitte versuchen Sie es spΓ€ter nochmal.", name: "AjaxError", stack: "@https://xxxxxxxxxxxxxxxxxxxxxxx/core/misc/ajax.js?v=10.1.5:196:32\n@https:xxxxxxxxxxxxxxxxxxxxxxx/core/misc/ajax.js?v=10.1.5:1889:3\n" }
ajax.js:196:32

if I deactivate "seasons" I can add a new exception day again

Admintration-Theme: Claro
Drupal-Version 10.1.5
PHP Version 8.2.11
MySQL Version 8.0.33
Apache

πŸ› Bug report
Status

Fixed

Version

1.12

Component

Code - widget

Created by

πŸ‡©πŸ‡ͺGermany blecheimer

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

Comments & Activities

  • Issue created by @blecheimer
  • πŸ‡³πŸ‡±Netherlands johnv

    Hmm,
    I use Claro myself.

    When does the error appear?
    - when you display the node form?
    - when you press [Add exception]?
    - when you enter data?
    - when you press [save]?

    Where does your file 'js-editor' come from? (mentioned in your original post)
    Which modules do you have installed?

  • πŸ‡©πŸ‡ͺGermany blecheimer

    I deleted the js-editor error because it does not is this error, it was something other in this module https://www.drupal.org/project/js_editor β†’ . If I disable it the error with seasons is still there

    When does the error appear?
    when I press [Add exception]?

  • πŸ‡³πŸ‡±Netherlands johnv

    did you check admin/config/development/logging, and set 'All messages, with backtrace information'?
    then, after a new test, is there anything under admin/reports/dblog ?

  • πŸ‡©πŸ‡ͺGermany blecheimer

    Does this help?

    Typ php
    Datum Freitag, 3. November 2023 - 18:12
    Standort https://---------------/node/14/edit?_wrapper_format=drupal_ajax&ajax_form=1
    Referrer https://---------------/node/14/edit
    Benachrichtigung LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in Drupal\Core\Database\Connection->__sleep() (Zeile 1712 in /------------------my host ------------------/web/core/lib/Drupal/Core/Database/Connection.php).
    Schweregrad Fehler

  • πŸ‡³πŸ‡±Netherlands johnv

    Can you disable first one, then the other module?
    I see no reason how the error should occur.

    You are not using Webform, correct?

  • πŸ‡©πŸ‡ͺGermany blecheimer

    hi, yes I'm also using webform in this installation but not on this edit page.
    ok I will test it on a test environment later.

  • πŸ‡©πŸ‡ͺGermany blecheimer

    Ok, I have tested it on the test environment with less modules than in the other drupal installation. I have the same problem there. (without Field Group https://www.drupal.org/project/field_group β†’ and Display Suite https://www.drupal.org/project/ds β†’
    a screenshot of the module list is attached

  • πŸ‡©πŸ‡ͺGermany blecheimer

    I have now disabled almost all custom modules. It is still the same.
    New module list is attached.

  • πŸ‡³πŸ‡±Netherlands johnv
  • πŸ‡³πŸ‡±Netherlands johnv

    I see the program passes the serialize() code. This happens before the custom 'addMoreAjax' is done.
    The form is cached, supposedly to fetch it later after the ajax call.
    Do you use a special database type?
    An alternative is that several fields are competing. Which fields are on your node? Does the error happen when the Node has only an Office Hours field (and Body). After the test, remove the Body field, too

  • πŸ‡³πŸ‡±Netherlands johnv

    I also found this issue #2461063: AJAX forms using #ajax broken when page caching is enabled β†’ .
    Please check what happens if 'Internal Page Cache' is disabled. This should only have effect when you edit a node as Anonymous user.
    This module has some problems with the 'Internal Page Cache' (page_cache) module.

    Do you edit as authenticated or anonymous user?

  • πŸ‡©πŸ‡ͺGermany blecheimer

    I edit only as authenticated user

  • πŸ‡³πŸ‡±Netherlands johnv

    No, I cannot reproduce the error. I use an XAMPP stack.

  • πŸ‡©πŸ‡ͺGermany blecheimer

    Ha! I've found it. it is something with the language

    testspace https://master-e5ulyfnh0vsxlh4hzkzvqpvr1vy4y6tg.tugboatqa.com/de/node/2

    (or try on your system:)

    perhaps one thing:
    enable language to german
    set language german to standard and interface language.

    switch to german edit interface

    perhaps the other thing:
    add office hours field to contenttype article.
    name the field "Γ–ffungszeiten" (machinename will be transliterated to: field_offnungzeiten)
    activate the widget "Office hours (week) with exceptions and seasons" with both seasons and exceptions

    now create a new article, try to add an exception. it fails.

  • πŸ‡³πŸ‡±Netherlands johnv

    interesting..

    I added the German language and used the 'Language Switcher' block to switch to German.
    Then, I opened the Node form. It is in German, but the button says 'Add exception'. (strange)
    Upon clicking on the button, no new exception appears (strange)
    But also, no message appears, even if I configured so (strange)

    The 'Last messages report' says your error:

    LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in Drupal\Core\Database\Connection->__sleep() (line 1712 of C:\damp\xampp\htdocs\drupal-10\core\lib\Drupal\Core\Database\Connection.php).

    You did not mean that the translation (with Umlaut) is the problem, not, but the German Language in general?

  • πŸ‡³πŸ‡±Netherlands johnv

    I also happens when I change to Dutch.

    My guess is it always happens when a language is added to the URL.
    - http://localhost/drupal-10/nl/node/8/edit also does generate an error.
    - http://localhost/drupal-10/node/8/edit does NOT genetare an error.
    Strangely enough, I cannot add the language 'en' to the URL --> 'Page not found'

    I core, I see several issues with the same problem. Many are 'cannot reproduce', which is not strange, as we see.
    LogicException problems β†’
    Also with German, and with BigPipe.

  • πŸ‡³πŸ‡±Netherlands johnv

    Disable BigPipe has no effect.

    Setting user language to German.
    http://localhost/drupal-10/de/node/8/edit gives error (with DE language from link)
    http://localhost/drupal-10/node/8/edit gives error, too (with DE language from user)

    In /admin/config/regional/language/detection , link goes before user.

    Setting user language to Dutch.
    no change, same errors.

    Setting user language to English.
    No error in http://localhost/drupal-10/node/8/edit (with DE language from user) :-)
    Page not found in http://localhost/drupal-10/de/node/8/edit gives error (with DE language from link)

    t.b.c.

  • πŸ‡©πŸ‡ͺGermany blecheimer

    My guess is it always happens when a language is added to the URL.

    No! My standard language is german, here is no language snippet in the url
    (Try it and set NL to standard language, then the snippet disappears)

    Also I don't think the Umlaut is a problem. Also not the german language but perhaps any language that is not english

    Please could you tell me where the button is in the code?
    and also the button of the seasons?
    (File and line number?)

  • πŸ‡©πŸ‡ͺGermany blecheimer

    but don't forget, the error is only there when Seasons is enabled. what is the difference?

  • πŸ‡³πŸ‡±Netherlands johnv

    Indeed, thanks for the 'seasons' hint.

    OK, so the problem is not with the URL, but it is still a problem with a non-EN form.

    When I read through the related issues in #18, a t() function is called on the page, that is cached upon the ajax call. this t() function, (or other classes) depend on an open database connection - which shouldn't be on a cached page.
    Solutions are to avoid this, by removing the requirements.

    It seems a fix like #2987548-15: LogicException: The database connection is not serializable. β†’ may fix the problem (but not in this case). That is the fix as intended by the message - which is clearly unclear.

    A test with disabling Internal Dynamic Page Cache and Internal Page Cache makes no difference.

    You can look for 'addMoreAjax' in the module code to find the triggering code in OfficeHoursExceptionsWidget.
    But OfficeHoursComplexWeekWidget::massageFormValues() combines both Exceptions and Seasons widgets in 1 form.

    Let me look what triggers the problem.

  • πŸ‡³πŸ‡±Netherlands johnv

    I found the problem and a solution - although the real solution should be in core.

    This is a 'season', with a translated name , and a 'stringTranslation')

    Drupal\office_hours\OfficeHoursSeason {#1874 β–Ό
      #id: 100
      #name: "Summer 2024"
      #from: 1719784800
      #to: 1724968800
      #stringTranslation: null
    }

    The solution is to remove the 'stringTranslation', which causes the problem.

    Several ways to get there, all in OfficeHoursSeason.php:
    - do not use $this->t() but t();
    - add use StringTranslationTrait;
    - do not add the Season object to the form.

    Please check attached patch.

    On that note, do you see any advantage in translating the Season title/name?

  • πŸ‡³πŸ‡±Netherlands johnv

    On a side note: I created πŸ› Add Translation context fallback for 'From', 'To' Active

  • πŸ‡©πŸ‡ͺGermany blecheimer

    On that note, do you see any advantage in translating the Season title/name?

    for me in this case, I don't need a translation, in other cases perhaps it could be useful.

    I will test it tomorrow

  • πŸ‡³πŸ‡±Netherlands johnv
  • πŸ‡©πŸ‡ͺGermany blecheimer

    yes worked after I deleted/not aplied this part:

    @@ -100,6 +102,7 @@ class OfficeHoursSeason {
         if (!is_numeric($this->to)) {
           $this->to = strtotime($this->to);
         }
    +dpm($this);
       }
    
  • πŸ‡³πŸ‡±Netherlands johnv

    That was quite some trip in core :-)

    It is fixed here: πŸ“Œ Remove translation from Season object (to avoid Ajax LogicException) Fixed

    I will keep this open for a while, since I am now intrigued by this problem: "Why are developers 'encouraged' to use $this->t() instead of old-school t(), and then all have to fix core problems?"

    Thanks for the fast cooperation. Please test dev-version.

  • πŸ‡©πŸ‡ͺGermany blecheimer

    hey sorry for delay. The last dev (Last updated: 8 Nov 2023 at 13:40 CET) does not work for me. I get a WSOD.
    I reverted back to working version with your patch.

  • πŸ‡³πŸ‡±Netherlands johnv

    Yeah, I did a half commit. Should be OK now. Sorry .

  • πŸ‡©πŸ‡ͺGermany blecheimer

    Ok worked, thank you!

  • Status changed to Needs work about 1 year ago
  • πŸ‡¨πŸ‡­Switzerland Lukas von Blarer

    The patch contains a call to dpm().

  • Status changed to Fixed about 1 year ago
  • πŸ‡³πŸ‡±Netherlands johnv

    Should be fixed now with change in πŸ› Multiple Office Hours fields on same Content Type breaks Exceptions Fixed

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024