Problem/Motivation

I'm using xmlsitemap 1.0.0 on Drupal 9.1.4 with Postgres 12.6.

In the database I see:

- taxonomy_term_field_data.tid | bigint
- node_field_data.nid | bigint
- xmlsitemap.id | varchar

Which causes xmlsitemap_xmlsitemap_index_links() (called via cron) to fail with:

 [error]  Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does NOT exist: bigint = character varying
LINE 5: ...'page')) AND ("node_field_data"."nid" NOT IN (SE...
                                                             ^
HINT:  No operator matches the given name AND argument types. You might need TO add explicit type casts.

and

[error]  Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: bigint = character varying
LINE 5: ...'category')) AND ("taxonomy_term_field_data"."tid" NOT IN (SE...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

For the node example, the query being executed is:

SELECT base_table.vid AS vid, base_table.nid AS nid
  FROM node base_table
       INNER JOIN node_field_data node_field_data
             ON node_field_data.nid = base_table.nid
 WHERE (node_field_data.type IN ('news', 'page'))
   AND (node_field_data.nid NOT IN
         (SELECT x.id AS id
            FROM xmlsitemap x
           WHERE type = 'node'))
 GROUP BY base_table.vid, base_table.nid
 LIMIT 100 OFFSET 0;

Steps to reproduce

drush xmlsitemap:index

Proposed resolution

Revert potential support for entities with string IDs.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork xmlsitemap-3201480

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jweowu created an issue. See original summary.

RoSk0’s picture

I traced the issue to the #2249723: Upgrade XML Sitemap to Drupal 8 and https://drupal.org/sandbox/andreimariusdincu/2222965 where the actual port to D8 was happening, but non of the issues in the sandbox are actually explicitly talking about support for entities with string IDs.

As far as I know most if not all content entities would use int as key and only content entities are supported as per xmlsitemap_is_entity_type_supported().

Updating proposed resolution to revert that change and make id key of xmlsitemap table int again.

Would be good to hear back from maintainers about proposed resolution.

RoSk0’s picture

Issue tags: +PostgreSQL
Dave Reid’s picture

It is still entirely possible that content entities may have string IDs. Core even has test coverage for this using a testing entity type named entity_test_string_id.

For reference:
#2555027: Support non-numeric entity ID's
#3057609: Add content moderation support for content entities with string IDs
#3109722: Entity IDs can be strings in Drupal 8

RoSk0’s picture

Hm, link to the core issue #3057609: Add content moderation support for content entities with string IDs just confirms that the support is only theoretical rather than actual.

What do you see as a solution to this issue?

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

Afxsoft’s picture

Here's a patch implementing solution

jweowu’s picture

At a glance, that's still assuming that ids should be integers, which Dave is saying isn't a valid assumption -- although it should hold for many (most?) cases.

If you're going to do this, though, I'd just directly modify the subquery to cast the value to an int in the first place.

Dave Reid’s picture

Status: Active » Needs work

For large amounts of data this will result in a possible very large array, which is why we use the subquery, which this change defeats the purpose of.

Dave Reid’s picture

Title: xmlsitemap_xmlsitemap_index_links() throws exception comparing entity IDs (bigint) to xmlsitemap IDs (varchar) » Queries throw exceptions comparing entity IDs (bigint) to xmlsitemap IDs (varchar) on PostgreSQL
Related issues: -#2249723: Upgrade XML Sitemap to Drupal 8 +#3079534: Views JOIN condition fails in PostgreSQL when comparing entity identifiers of different datatypes, +#2864440: PostgreSQL problems on entity_id of type varchar with flagging and flag_count tables, +#2564307: [meta] Remaining Drupal 10/11 PostgreSQL issues

Our new xmlsitemap_post_update_reindex_future_revision_content() function also fails in the same exact way, since we want to join an entity table against the xmlsitemap table in a subquery. Merging that issue into this one since it will need the same fix. Cross-linking some other modules or core issues about the same issue, I can't find a solution that anyone has done yet.

mparker17’s picture

Status: Needs work » Reviewed & tested by the community

I've tested both this issue's patch ( https://git.drupalcode.org/project/xmlsitemap/-/merge_requests/9.diff ) and the add-entity-query-method branch (which fixes the same issue at a lower level, i.e.: XmlSitemapLinkStorage).

Honestly, I like the approach in the add-entity-query-method branch better - and it fixes the error I was getting (see below) - but since there's no merge request and no corresponding issue, I don't have a way to provide any feedback on the branch except here (sorry!)

I'm going to tentatively mark this ticket as RTBC because the patch in this issue fixes the error I was getting while rebuilding my xmlsitemap...

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: bigint = character varying LINE 5: ... AND (node_field_data.nid NOT IN (SE... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.: SELECT base_table.vid AS vid, base_table.nid AS nid FROM {node} base_table INNER JOIN {node_field_data} node_field_data ON node_field_data.nid = base_table.nid WHERE (node_field_data.type IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2)) AND (node_field_data.nid NOT IN (SELECT x.id AS id FROM {xmlsitemap} x WHERE type = :db_condition_placeholder_3)) GROUP BY base_table.vid, base_table.nid LIMIT 100 OFFSET 0; in xmlsitemap_xmlsitemap_index_links() (line 1632 of web/modules/contrib/xmlsitemap/xmlsitemap.module).

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: xmlsitemap-bigint-issue.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Dave Reid’s picture

Status: Needs work » Needs review

I moved my branch code to a MR associated with this issue for better review.

  • Dave Reid committed 8bc8ca1 on 8.x-1.x
    Issue #3201480 by Dave Reid, Afxsoft: Fixed queries throw exceptions...
Dave Reid’s picture

Status: Needs review » Fixed

Given that it's passing tests, I'm going to commit this and include it in the next release here.

  • Dave Reid committed 8bc8ca1 on 2.x
    Issue #3201480 by Dave Reid, Afxsoft: Fixed queries throw exceptions...

Status: Fixed » Closed (fixed)

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