This error pops up on Postgres. Other engines seems silently to ignore it. Attached a very simple example view that allow you to enter a nid as argument.

Reproduce error

  • Install on PostgreSQL 9.1/92
  • Clean Drupal 7 and views (latest stable or HEAD).
  • Install view
  • Import attached view.
  • If you like create a few test nodes.
  • Load the views page and verify that it lists the nodes
  • Enter a nid as a argument and verify that is works as expected.
  • Enter a string as argument and you should get a beautiful PDOException

PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "foo" LINE 1: SELECT n.title FROM node n WHERE n.nid IN ('foo') ^: SELECT n.title FROM {node} n WHERE n.nid IN (:nids_0); Array ( [:nids_0] => foo ) in views_handler_argument_node_nid->title_query() (line 18 of /prototype/views/drupal-7.17/sites/all/modules/views/modules/node/views_handler_argument_node_nid.inc).

I think it is this code is what fails.

<?php
  function validate_argument_basic($arg) {
    if (!isset($arg) || $arg === '') {
      return FALSE;
    }
    if (!empty($this->definition['numeric']) && !isset($this->options['break_phrase']) && !is_numeric($arg)) {
      return FALSE;
    }
    return TRUE;
  }
?>

Debugging this and I get this where it fails and it is indeed returning TRUE when I should return FALSE.
Is it numeric?: 1
break_phrase: 0
arg: sfdf
returns TRUE

CommentFileSizeAuthor
views_argument.txt2.39 KBsteinmb
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

What happens if you choose "Numeric" as validator? From my understanding this should validate the actual argument in the way you want.

Chi’s picture

Title: validate_argument_basic() return TRUE when nid is not_numeric » PDOException:Invalid text representation when attempting to load a view with a string argument
Project: Views (for Drupal 7) » Drupal core
Version: 7.x-3.x-dev » 8.x-dev
Component: Code » base system
Priority: Major » Normal
Status: Active » Closed (duplicate)

You need not install views to reproduce the bug. Just type something like node/blablabla on Postgres installation of Drupal.
Marking as duplicate of #1003788: PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID.

Drupa1ish’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Closed (duplicate) » Active
Issue tags: +PostgreSQL
dcam’s picture

Which issue? The problem with Views arguments?

Drupa1ish’s picture

@dcam, yes