Problem/Motivation

The logic for field lengths is incorrect, e.g. setting a field to a max size of 64kb results in an error that says the value can't be more than 4kb.

Steps to reproduce

Add a JSON "text" field to a content type, set the limit to 64kb.
Create a node of that content type, paste in Drupal's composer.json content.

Expected behavior:
* The node saves.

Actual behavior:
* This error is shown: JSON: the text may not be longer than 4096 characters.

Proposed resolution

Fix the field length logic.

Remaining tasks

Fix the field length logic.
Add test coverage.

User interface changes

Field lengths will work correctly.

API changes

n/a

Data model changes

n/a

Issue fork json_field-3532075

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

damienmckenna created an issue. See original summary.

damienmckenna’s picture

Status: Active » Needs work

This needs an update script to fix existing fields that have the wrong size.

damienmckenna’s picture

Assigned: damienmckenna » Unassigned

eric.vvf made their first commit to this issue’s fork.

eric.vvf’s picture

eric.vvf’s picture

Status: Needs work » Needs review
damienmckenna’s picture

Thank you for writing the update script. I converted it to a post-update script, as that's a better location for dealing with configuration.

damienmckenna’s picture

Status: Needs review » Reviewed & tested by the community
Parent issue: » #3465996: Plan for JSON Field 8.x-1.6

  • damienmckenna committed a707f4b2 on 8.x-1.x
    Issue #3532075 by damienmckenna, eric.vvf: Fixed field length limit...
damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thank you.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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

nicholass’s picture

So Just updating today and I am getting an error from this change.
Drupal core 10.5.3
- Upgrading drupal/json_field (1.5.0 => 1.7.0)

------------ ---------------- --------------- ------------------------------------------------------------------------------
Module Update ID Type Description
------------ ---------------- --------------- ------------------------------------------------------------------------------
json_field fix_field_size post-update Empty update script to force the system to reload the field_type_categories.
------------ ---------------- --------------- ------------------------------------------------------------------------------

// Do you wish to run the specified pending updates?: yes.

> [warning] Undefined array key "type" views.views.inc:594
> [notice] Update started: json_field_post_update_fix_field_size
> [error] Failed to update field storage field_pg_jsonsettings: The SQL storage cannot change the schema for an existing field (field_pg_jsonsettings in paragraph entity) with data.
> [notice] Update completed: json_field_post_update_fix_field_size
[success] Finished performing updates.
[warning] Undefined array key "type" views.views.inc:594

cyxair’s picture

I encounter the same behavior on all Drupal 10 websites using this module.

json_field.post_update.php breaks updated on a website with existing data.

Last viable version of json_field module is 8.x-1.5.

damienmckenna’s picture

Please open a new issue and we'll work on this.

xurizaemon’s picture

Opened #3553199: Invalid schema for unexpected JSON (text) field size 16384 with related issue and fix I observed upgrading from 8.x-1.4 to 8.x-1.7.