Problem/Motivation

The request_uri field is limited to 255 characters, but URIs might be up to around 2048 characters. Long URIs cause errors because the field is too small, eg:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'request_uri' at row 1: INSERT INTO "rest_log"

Steps to reproduce

Make an API request where the URI is super long.

Proposed resolution

Change the request_uri field to be a long_string, instead of a string.

Data model changes

Change the request_uri field to be a long_string, instead of a string.

Issue fork rest_log-3457557

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

JKingsnorth created an issue. See original summary.

jkingsnorth’s picture

Assigned: jkingsnorth » Unassigned

Oh man I thought this was going to be straightforward, but it looks like that isn't the case. there's a whole developer module (https://git.drupalcode.org/project/field_type_converter/-/blob/1.0.x/src...) which supports field type changes because it needs a new field creating rather than updating the existing one? Am I missing something here?

jkingsnorth’s picture

Version: 8.x-1.x-dev » 2.2.0
Status: Active » Needs review

Right, I found some guidance here https://www.drupal.org/docs/drupal-apis/update-api/updating-entities-and... and had a go at this change based on that documentation. Here's a MR: https://git.drupalcode.org/project/rest_log/-/merge_requests/13

Would appreciate thoughts/feedback. My concern is that the update could take a long time to apply if there is a lot of data in the table!

ad0z made their first commit to this issue’s fork.

ad0z’s picture

@JKingsnorth I don't think there is a need to update field type from string to long_string, as string is representation of varchar which max lenght is 65,535 characters.. and as you mention we would have to take care of migration data, I don't think foreach and single update query would be a good idea, because it would take too much time for bigger sets of data. (maybe chunks could be better.. still it's not needed in my opinion)
I've created simple hook update to set column schema length value to 2048, and added needed changes to rest_log entity to apply it to new installations.
Could you test it and review the merge request? https://git.drupalcode.org/project/rest_log/-/merge_requests/14

  • ad0z committed f8e4a0d2 on 2.x
    Issue #3457557 by ad0z, JKingsnorth, zviryatko: Longer field for...

ad0z credited zviryatko.

ad0z’s picture

Status: Needs review » Fixed

I've added explicitly limiting of request_uri to 2048 characters to prevent errors when it exceeds the max length. Merge request merged to 2.x.

Status: Fixed » Closed (fixed)

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

jkingsnorth’s picture

Thanks for the fix, apologies for the delayed response.