Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291614

Drupal 8 only allows one user every 6 hours to register when page caching is enabled — caused by entity UUID in form state

$
0
0

Problem/Motivation

Over at #606840-78: Enable internal page cache by default, we have a bunch of failures in UserRegistrationTest. The failures happen after registering two users. The fatal error is caused by a SQL error:

[31-Mar-2015 15:47:14 Europe/Brussels] Uncaught PHP Exception Drupal\Core\Entity\EntityStorageException: "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '4a0944f2-9f46-4187-9f09-9b3743105ef6' for key 'user_field__uuid__value': INSERT INTO {users} (uid, uuid, langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array

STR

  1. Enable page cache.
  2. Log out.
  3. Go to /user/register
  4. Register once.
  5. Register again. BOOM! SQL error.

Root cause

  1. All entity forms set the entity-being-built in form state.
  2. This means all entity forms use the form cache.
  3. Form state/form cache are tied to the form build ID.
  4. The form build ID is present in the HTML.
  5. Enabling page caching (or any reverse proxy for anon users) ⇒ HTML is cached ⇒ same form build ID used for all anon users ⇒ same form cache/form state used for all anon users.
  6. So far, no problems. The final, lethal ingredient: creating a (content) entity also means generating a UUID ⇒ the entity in form state, that is used for all users, already has a UUID.

Conclusion: every user signing up at /user/register is going to get the same UUID for 6 hours (that's the default form state TTL). That doesn't quite work, obviously.

Proposed resolution

  • Don't let UuidItem::applyDefaultValue() create a UUID (this is called when creating an entity)
  • Instead, let ContentEntityBase::uuid() create it.

Remaining tasks

Review.

User interface changes

None.

API changes

Unsure.


Viewing all articles
Browse latest Browse all 291614

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>