Sometimes not possible to vote 'The specified #ajax callback is empty or not callable'

Created on 11 February 2022, almost 3 years ago
Updated 16 November 2023, about 1 year ago

I don't sure how to reproduce this issue, however, our clients report an error when they use VPN.
I have a look into the module and found a place responds on this 'callback' => '::ajaxReplaceForm'.
Going to provide a solution.

🐛 Bug report
Status

Needs work

Version

1.0

Component

User interface

Created by

🇺🇦Ukraine Ruslan Piskarov Kiev, Ukraine

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India nitesh624 Ranchi, India

    Tried the steps mentioned in #5 but not able to reproduce

  • 🇮🇳India nitesh624 Ranchi, India

    This issue seems to be intermittent.

  • 🇮🇳India nitesh624 Ranchi, India

    So I spent few days to get the steps to reproduce this issue

    • I spin up a D10 site in https://simplytest with poll module
    • I have allowed anonymous voting
    • I am connected to VPN on my system
    • Not I Visited the poll url on chrome browser, I was able to vote
    • Now I changed the network on my system and reconnected the vpn
    • Now I visited the poll page on Chrome browser I am getting vote results
    • Now I visited the poll page on Edge browser
    • Then I am getting poll form and on clicking the vote button i am getting ajax error
    • "Symfony\Component\HttpKernel\Exception\HttpException: The specified #ajax callback is empty or not callable. in Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse() (line 67 of /var/lib/tugboat/stm/web/core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php).
    • But When I cleared the drupal cache. the poll paeg shows the vote results
  • 🇮🇳India nitesh624 Ranchi, India

    But if I add
    $form['#cache]['max-age] = 0; in the src/Form/PollViewForm.php file line 114 before the return $form statement. The issue is no longer coming up.
    So I assume something

  • ivnish Kazakhstan

    Same problem

  • 🇮🇳India nitesh624 Ranchi, India

    ivnish are you able to reproduce this issue?

  • ivnish Kazakhstan

    I can reproduce this:

    I opened Firefox private tab, voted, close tab, open new private tab and got error when voted again

  • ivnish Kazakhstan

    If I clear Drupal cache, I need to remove my previous anonymous vote from DB to reproduce this again

  • ivnish Kazakhstan

    The patch from MR doesn't help me

  • 🇮🇳India nitesh624 Ranchi, India

    Yes for me also patch doesn't seems to be solving the issue

  • 🇮🇳India nitesh624 Ranchi, India

    In the PollViewForm.php I have added
    \Drupal::service('page_cache_kill_switch')->trigger(); on Line 86 under else section.
    After that it seems to be working fine.

    As I saw in function showPollResults() already we have \Drupal::service('page_cache_kill_switch')->trigger(); line at top.
    So probably this issue could be due to this page_cache.

  • ivnish Kazakhstan

    I created a patch with #18 fixes. Please review and test

  • 🇨🇭Switzerland berdir Switzerland

    If you get this error, then that means that you are not allowed to vote because that IP already voted. The "only" problem here is that there is a strange error instead of getting that feedback.

    The reason for that is that on the POST request, the form is built differently as a result of no longer having access, doesn't have a submit vote anymore and the core form/ajax system is confused about that.

    Just completely disabling page cache is _not_ the answer, that will obviously disable page cache on on any page with a poll, if you have that on the frontpage, or on article sidebars or something, that's going to hurt you.

    One solution I see here is to catch and handle that error in a nicer way, possibly either through a request subscriber (detect the problem before it happens, return info that voting isn't allowed anymore for this IP), or a response subscriber (detect the exception, do the same).

    Or maybe do some trickery that still adds the vote button on such cases on ajax post requests but it's submit action will then not actually do anything but display a message.

    Or change core to not explode like this on ajax requests, but not sure what to do instead then there.

  • 🇮🇳India nitesh624 Ranchi, India

    Thank @berdir to pitching in.
    Is there any way we can disable the cache on form. I tried setting max-age=0 on form build array. but still the problem persists.

    One solution I see here is to catch and handle that error in a nicer way, possibly either through a request subscriber (detect the problem before it happens, return info that voting isn't allowed anymore for this IP), or a response subscriber (detect the exception, do the same).

    For this approach where we can use request subscriber.? I am not able to understand approach.

  • 🇮🇳India nitesh624 Ranchi, India

    I am able to show the warning message to user using response subscriber.

    But still I am not able to understand why this is not happening on my local instance. Its happening only for hosted env. Is it because of IP restriction?

  • 🇮🇳India nitesh624 Ranchi, India

    I am checking the http response code, if the request is ajax request and the route is of poll entity then I am checking if already poll exits for that Ip address then replacing the form with status message on page.

  • 🇮🇳India nitesh624 Ranchi, India

    Now I am able to replicate this issue locally also with fresh vanilla drupal 10.1 installation.

  • 🇬🇧United Kingdom aps-Andrew

    Is there any movement on this? I saw it start to get updated and replicated at the end of last year and was hoping to run some stress tests against the polling, but was hoping this issue might be resolved before that time so that the stress test isn't potentially experiencing the same issue.

  • 🇮🇳India drupalite1411

    Any update on this issue?
    Facing this in the modules' latest version as well.

  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    In any case this needs exact steps to reproduce as I still have never encountered this error myself. And once we have those steps, create a test for it.

    We need a rebase on the 2.0.x branch with a proper fix, just disabling cache like explained in #20 is not the solution. If needed this is something we could backport as it's a bug.

  • 🇮🇳India drupalite1411

    Steps to replicate:
    1)Vote from any browser
    https://www.drupal.org/files/issues/2024-11-13/poll.png
    2)Open voting page in incognito. It should show the polling result page since I am in the same network(connected to vpn).
    Instead, it is showing voting page with vote button.
    3)Click on vote button, it shows ajax error.
    https://www.drupal.org/files/issues/2024-11-13/poll2.png

  • 🇮🇳India drupalite1411

    If this makes any difference in the bug tracking, https://www.drupal.org/project/poll/issues/2909811 📌 Anonymous users - Multiple voting from one IP Needs review this resolves ajax issue for per IP vote.
    Need to find the difference how per IP voting has been changed in this merge request.

  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    RE #29 probably only when anonymous voting is enabled? There are some PK changes in the database for that ticket.

    I think the underlaying error here is that the database is throwing an duplicate entry exception which is not catched properly because here it's still using the IP as unique key if I'm not mistaken.

  • 🇮🇳India drupalite1411
    RE #29 probably only when anonymous voting is enabled? There are some PK changes in the database for that ticket.

    Yes that is for anonymous user.

    I think the underlaying error here is that the database is throwing an duplicate entry exception which is not catched properly because here it's still using the IP as unique key if I'm not mistaken.

    Yes it seems so but I don't understand why it is showing incognito mode only and not in another browser. I am debugging on that

  • 🇮🇳India drupalite1411

    Debugging output:
    I was unable to replicate this issue in Dev environment and could replicate this in patheon env or with https://simplytest.me/
    I have enabled page cache in my Dev enviornment and I can see the issue in every browser.
    Steps to replicate:
    1)Open voting page it in chrome and vote.
    2)Open same voting page in edge and you will see the vote button instead of result.
    3)On clicking vote ,it will show the ajax error.
    4)If remove chrome browser cookie and then open it in other browser then there is no ajax error and I can see the result page.
    I could see https://www.drupal.org/project/poll/issues/2909811 📌 Anonymous users - Multiple voting from one IP Needs review ajax error per IP with this https://www.drupal.org/project/poll/issues/2909811 📌 Anonymous users - Multiple voting from one IP Needs review on as well.

Production build 0.71.5 2024