Problem/Motivation

The entity_mesh module does not validate field values before inserting them into the database. When processing batch operations with malformed link data, the module attempts to insert oversized values into database columns, causing INSERT queries to fail with truncation errors.

Currently, when an INSERT fails due to data validation issues (e.g., string data too long for a column), the batch process halts with a database error rather than gracefully handling the failed item. This prevents the batch operation from completing and makes it difficult to identify which specific items caused the failure.

Error encountered:

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'target_host' at row 4

In this case, the target_host column received a full URL or text content instead of just the hostname portion, exceeding the column's character limit.

Steps to reproduce

  1. Create a content entity (e.g., node) with render links containing malformed or oversized data
  2. Configure entity_mesh to track links for this entity type
  3. Trigger a batch operation to process entity_mesh data (e.g., via cron or manual batch execution)
  4. Include a link where:
    • target_host contains a full sentence or paragraph instead of just the hostname (e.g., "This is a very long description that should not be in the hostname field")
    • Or any field contains data that exceeds its database column size constraint
  5. The batch process will fail with a database truncation error and stop processing

Example data structure that causes the issue:

INSERT INTO "entity_mesh" (..., "target_host", ...) VALUES 
(..., "example.com", ...), 
(..., "cdn.example.org", ...), 
(..., "www.example.net", ...), 
(..., "This is a very long text description that exceeds the column size limit", ...)

Proposed resolution

Implement validation for all entity_mesh fields before database insertion:

  1. Add field validation logic that checks:
    • String field lengths against their database column constraints
    • Required fields are populated
    • URL components (scheme, host, path) are correctly formatted
    • Entity references point to valid entities
  2. Handle validation failures gracefully:
    • Catch validation errors before INSERT attempts
    • Log failed items with detailed error information
    • Mark failed items in the batch tracker so they can be:
      • Retried later
      • Reported to administrators
      • Excluded from causing batch failure
  3. Allow batch processing to continue even when individual items fail validation, similar to how robust batch operations handle partial failures
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

lpeidro’s picture

I believe this should be treated as an error during content processing. We should implement a way to handle cases where the URL is incorrectly built and categorize them under a new type: invalid-urls. These invalid URLs should not be analyzed by the entity mesh like external links are. Instead, they should be added to the table for further correction.

lpeidro’s picture

Status: Active » Needs review

We have also used this tag to implement validation for URLs and telephone numbers. Now, before starting any analysis process, the entity mesh validates both the URLs and phone numbers. If they do not pass validation, the analysis is not executed for those cases. However, they are still inserted into the result table and flagged with two new subcategories: invalid-url and invalid-tel.

It is ready for testing.

lpeidro’s picture

Status: Needs review » Reviewed & tested by the community

Rwviewed and tested. I merge the branch.

lpeidro’s picture

Version: 1.x-dev » 1.2.3
Status: Reviewed & tested by the community » Fixed

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

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

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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