Problem/Motivation

Can't add constraint.

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /admin/config/system/password_policy/constraint/add/default/character_types?ajax_form=1
StatusText: parsererror
ResponseText: Error: Call to a member function getConstraints() on null in Drupal\password_policy\Form\ConstraintEdit->submitForm() (line 145 of /var/www/html/web/modules/contrib/password_policy/src/Form/ConstraintEdit.php)."

Steps to reproduce

Install password policy. Install Password Character Types Policy and Password Characters of Type Policy. Add Policy and try to add constraint.

Go to the logs and you will see this message:

Error: Call to a member function getConstraints() on null in Drupal\password_policy\Form\ConstraintEdit->submitForm() (line 145 of /app/web/modules/contrib/password_policy/src/Form/ConstraintEdit.php)

Comments

danthorne created an issue. See original summary.

danthorne’s picture

Title: Can add constraint. Ajax error. » Can't add constraint. Ajax error.
adriancid’s picture

Title: Can't add constraint. Ajax error. » Error: Call to a member function getConstraints() on null
Issue summary: View changes
adriancid’s picture

Version: 8.x-3.1 » 8.x-3.x-dev
adriancid’s picture

I have the module installed on two different sites and in one of them I have the problem with version 3.1.0 and dev and Drupal 9.4.2 and in the other with version 3.1.0 and Drupal 9.3.16 is working I don't know if it is related to the Drupal version or it is related to another module causing the problem.

danthorne’s picture

My version of Drupal with the issue is Drupal 9.4.2

fskreuz’s picture

The issue is that ctools switched from shared tempstore in 3.7 to private tempstore in 3.8 to fix a concurrent edit issue. This caused issues on dependent modules (e.g. password_policy, page_manager, etc.) that explicitly use tempstore.shared. The issue is because tempstore.shared cannot read entries added by tempstore.private, the cached values are present but cannot be read.

The quick fix for now is to pin your ctools version to 3.7.

The longer term fix is to remove ctools dependency (see https://www.drupal.org/project/password_policy/issues/2877040)

If you're adventurous, attached is a patch that switches tempstore.shared to tempstore.private for password_policy. Do note that the ctools fix done in 3.8 is somewhat incomplete, as it only switched storages for a certain portion of ctools. There might still be cases within ctools where it stores data with one but tries to read with the other, the attached patch might still not work (I ended up patching ctools to use tempstore.private for all the things).

adriancid’s picture

Status: Active » Reviewed & tested by the community

The patch fix the problem and now I'm able to add the policies.

adriancid’s picture

Status: Reviewed & tested by the community » Needs work

I don't know if is related but I'm able to create the policies but they are not visible in the user registration form

adriancid’s picture

Status: Needs work » Reviewed & tested by the community

Sorry is working, I added the policies in Dev and was checking on my local :-D LOL

paulocs’s picture

Hello, can you confirm if you are still having this issue in the dev branch?
We have removed the ctools dependency in #2877040: Remove dependency on CTools

vselivanov’s picture

Works for me with Drupal 9.4, Ctools 3.11 and Password Policy 3.x-dev. Dependency was removed and error fixed.

paulocs’s picture

Status: Reviewed & tested by the community » Fixed

So moving to fixed. New releases will come soon. #3305839: Create Password Policy 8.x-3.2 release

Status: Fixed » Closed (fixed)

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