Problem/Motivation

When I create a new field on an entity (via the UI), I get this error:

The website encountered an unexpected error. Please try again later.
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'url' at row 1: INSERT INTO {purge_queuer_url} (url, tag_ids) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => https://example.com/admin/structure/page/2_column/fields/page.2_column.field_description/storage?destinations%5B0%5D%5Broute_name%5D=entity.field_config.page_field_edit_form&destinations%5B0%5D%5Broute_parameters%5D%5Bfield_config%5D=page.2_column.field_description&destinations%5B0%5D%5Broute_parameters%5D%5Bpage_type%5D=2_column&destinations%5B1%5D%5Broute_name%5D=entity.page.field_ui_fields&destinations%5B1%5D%5Broute_parameters%5D%5Bfield_config%5D=page.2_column.field_description&destinations%5B1%5D%5Broute_parameters%5D%5Bpage_type%5D=2_column&destinations%5B2%5D=%2Fadmin%2Fstructure%2Fpage%2F2_column%2Ffields%2Fadd-field [:db_insert_placeholder_1] => ;529325;529326;529327;529328;529329;529330;529331;529332;529333;529334;529339;529340;529341;529400;529402;529492 ) in Drupal\purge_queuer_url\StackMiddleware\TrafficRegistry->add() (line 57 of modules/contrib/purge_queuer_url/src/StackMiddleware/TrafficRegistry.php).

Drupal\purge_queuer_url\StackMiddleware\TrafficRegistry->add('https://example.com/admin/structure/page/2_column/fields/page.2_column.field_description/storage?destinations%5B0%5D%5Broute_name%5D=entity.field_config.page_field_edit_form&destinations%5B0%5D%5Broute_parameters%5D%5Bfield_config%5D=page.2_column.field_description&destinations%5B0%5D%5Broute_parameters%5D%5Bpage_type%5D=2_column&destinations%5B1%5D%5Broute_name%5D=entity.page.field_ui_fields&destinations%5B1%5D%5Broute_parameters%5D%5Bfield_config%5D=page.2_column.field_description&destinations%5B1%5D%5Broute_parameters%5D%5Bpage_type%5D=2_column&destinations%5B2%5D=%2Fadmin%2Fstructure%2Fpage%2F2_column%2Ffields%2Fadd-field', Array) (Line: 147)
Drupal\purge_queuer_url\StackMiddleware\UrlRegistration->set(Object, Object) (Line: 95)
Drupal\purge_queuer_url\StackMiddleware\UrlRegistration->handle(Object, 1, 1) (Line: 62)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 55)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 31)
Drupal\gc_api\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 637)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

Either

  1. Increase the length of the URL field in the database
  2. Ensure that the length of the URL is not too long before attempting to insert it.

Remaining tasks

  1. Get maintainer to pick a direction
  2. Write Patch

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

davidwbarratt created an issue. See original summary.

nielsvm credited nielsvm.

nielsvm’s picture

I've written and tested this:

diff --git a/src/StackMiddleware/TrafficRegistry.php b/src/StackMiddleware/TrafficRegistry.php
index 153cefa..51859bf 100644
--- a/src/StackMiddleware/TrafficRegistry.php
+++ b/src/StackMiddleware/TrafficRegistry.php
@@ -45,6 +45,14 @@ class TrafficRegistry extends ServiceProviderBase implements TrafficRegistryInte
       throw new \LogicException('$tags cannot be empty!');
     }
 
+    // Sometimes Drupal generates ridiculously long URLs that pass well over the
+    // VARCHAR max length of 255, for example with the ?redirect parameters. We
+    // dismiss these URLs here, as using bigger datatypes ain't worth the
+    // trade-off and would make this module even more expensive to use.
+    if (strlen($url_or_path) > 255) {
+      return;
+    }
+
     // Build a list of tag IDs by adding and or selecting them from the db.
     $tag_ids = ';' . implode(';', array_keys($this->getTagIds($tags)));
 
diff --git a/src/StackMiddleware/TrafficRegistryInterface.php b/src/StackMiddleware/TrafficRegistryInterface.php
index f0a448f..f8dd610 100644
--- a/src/StackMiddleware/TrafficRegistryInterface.php
+++ b/src/StackMiddleware/TrafficRegistryInterface.php
@@ -18,6 +18,11 @@ interface TrafficRegistryInterface extends ServiceProviderInterface, ServiceModi
   /**
    * Register a new URL or path with its associated cache tags at the registry.
    *
+   * @warning
+   *   Implementation specific contstraints - such as database field length -
+   *   might dismiss the URL being added. Although implementations should
+   *   prevent this from happening at all cost, it could happen.
+   *
    * @param string $url_or_path
    *   The URL or path string to register (may already exist).
    * @param string[] $tags

So that means that these horribly URLs will be dropped instead of stored, I think this should be considered a tiny inconvenience in practice. Given that this module is a "fall back" solution for providers that don't (yet) have tag-based invalidation, the fact that some URLs with long redirection or queries/hex data embedded in them won't get cleared... might even be a not-so-bad thing.

Will release this shortly so it can be tested.

nielsvm’s picture

Status: Active » Fixed

Not perfectly following process but highly sure that its fixed, feel free to put back when the next release might not yet catch everything.

Status: Fixed » Closed (fixed)

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