• Tried to create a redirect on a site, got this big error message (sanitized only for the domain name):

    Plugin: 3.5
    WordPress: 4.9.8 (single)
    PHP: 7.2.10
    Browser: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36
    JavaScript: https://mysite.edu/wp-content/plugins/redirection/redirection.js
    REST API: https://mysite.edu/wp-json/

    Error: Unable to add new redirect (29): Incorrect integer value: ” for column ‘regex’ at row 1
    Action: redirection/v1/redirect/ POST
    Params: {“id”:0,”url”:”/obs/data-request-instructions/”,”title”:””,”regex”:false,”match_type”:”url”,”action_type”:”url”,”position”:0,”group_id”:4,”action_code”:301,”action_data”:{“url”:”/our-research/observational-study/dian-observational-study-investigator-resources/data-request-terms-and-instructions/”}}
    Code: 400 Bad Request
    Raw: {“code”:”redirect”,”message”:”Unable to add new redirect”,”data”:{“status”:400,”error_code”:29,”wpdb”:”Incorrect integer value: ” for column ‘regex’ at row 1″}}

    The PHP error log had a more detailed copy of the error, with the full query:

    [19-Oct-2018 15:13:49 UTC] WordPress database error Incorrect integer value: ” for column ‘regex’ at row 1 for query INSERT INTO d_redirection_items (regex, url, title, group_id, position, action_type, action_code, match_type, action_data, status) VALUES (”, ‘/obs/data-request-instructions/’, ”, ‘4’, ‘0’, ‘url’, ‘301’, ‘url’, ‘/our-research/observational-study/dian-observational-study-investigator-resources/data-request-terms-and-instructions/’, ‘enabled’) made by Red_Item::create

    Looks like that column is expecting an integer, and the query is specifying a blank value (not a null, and not an integer).

    The backing database is actually MariaDB, not MySQL, but I’ve rarely encountered an instance where that matter.

    This was just while creating a fairly standard plugin, but I think this site is one where the Redirection plugin was just recently installed.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author John Godley

    (@johnny5)

    Interesting. This should be handled by the default settings, but it’s possible your MySQL doesn’t like this. The next version will set the regex value explicitly and you shouldn’t see this message.

    Thread Starter David E. Smith

    (@desmith)

    On a different site, recently moved between our old and new hosting environments, we got a variation on a theme:

    Error: Unable to add new redirect (29): Field ‘last_access’ doesn’t have a default value
    Raw: {“code”:”redirect”,”message”:”Unable to add new redirect”,”data”:{“status”:400,”error_code”:29,”wpdb”:”Field ‘last_access’ doesn’t have a default value”}}

    In this case, the “old” site was PHP 5.3 and MariaDB 10.1; the “new” one is the same as above (PHP 7.2, MariaDB 10.2). The site was moved with a simple mysqldump. Maybe there’s a quirk in 10.2, or different handling of default values?

    (Internally, things are even more complicated with HyperDB, but we’re only using it for read replication balancing, not for anything like sharding. That shouldn’t matter here, but …)

    Plugin Author John Godley

    (@johnny5)

    Could you show the create table SQL for your wp_redirection_items table? There is a default value set for last_access, but I wonder if it’s present on yours, or maybe doesn’t work in a particular version

    Thread Starter David E. Smith

    (@desmith)

    First, the “old” PHP 5.3/MariaDB 10.1 environment. I looked both at a mysqldump, and ran a SHOW CREATE TABLE query, and they appear to be identical.

    CREATE TABLE med_redirection_items (
    id int(11) unsigned NOT NULL AUTO_INCREMENT,
    url mediumtext NOT NULL,
    regex int(11) unsigned NOT NULL DEFAULT ‘0’,
    position int(11) unsigned NOT NULL DEFAULT ‘0’,
    last_count int(10) unsigned NOT NULL DEFAULT ‘0’,
    last_access datetime NOT NULL,
    group_id int(11) NOT NULL DEFAULT ‘0’,
    status enum(‘enabled’,’disabled’) NOT NULL DEFAULT ‘enabled’,
    action_type varchar(20) NOT NULL,
    action_code int(11) unsigned NOT NULL,
    action_data mediumtext,
    match_type varchar(20) NOT NULL,
    title text,
    PRIMARY KEY (id),
    KEY url (url(200)),
    KEY status (status),
    KEY regex (regex),
    KEY group_idpos (group_id,position),
    KEY group (group_id)
    ) ENGINE=InnoDB AUTO_INCREMENT=564 DEFAULT CHARSET=utf8

    Then, I migrate the data to our new environment. The migration is a shell script, that does a mysqldump from the old server, then an import to the new one. After that process is done, here’s the output of a SHOW CREATE TABLE in the new PHP 7.2/MariaDB 10.2 environment:

    CREATE TABLE med_redirection_items (
    id int(11) unsigned NOT NULL AUTO_INCREMENT,
    url mediumtext NOT NULL,
    regex int(11) unsigned NOT NULL DEFAULT 0,
    position int(11) unsigned NOT NULL DEFAULT 0,
    last_count int(10) unsigned NOT NULL DEFAULT 0,
    last_access datetime NOT NULL,
    group_id int(11) NOT NULL DEFAULT 0,
    status enum(‘enabled’,’disabled’) NOT NULL DEFAULT ‘enabled’,
    action_type varchar(20) NOT NULL,
    action_code int(11) unsigned NOT NULL,
    action_data mediumtext DEFAULT NULL,
    match_type varchar(20) NOT NULL,
    title varchar(50) DEFAULT NULL,
    PRIMARY KEY (id),
    KEY url (url(200)),
    KEY status (status),
    KEY regex (regex),
    KEY group_idpos (group_id,position),
    KEY group (group_id)
    ) ENGINE=InnoDB AUTO_INCREMENT=551 DEFAULT CHARSET=utf8

    So, in the old one, the default values for the int columns are shown as ‘0’ but for the new version they’re just 0 (maybe some sort of typing, or maybe just a change in how the output is displayed). The action_data column seems to have picked up a DEFAULT NULL that I’m not sure where it came from, and the title column has changed types altogether. I’m so very confused right now, it looks like somehow the database itself is sabotaging me.

    I’m trying to find documentation on any sort of implicit type changes between MariaDB 10.1 and 10.2. Haven’t found it yet, but the day is young.

    (The auto-increment counters being different isn’t surprising since I did the last instance of copying this site from the current production environment, to the new one, a few days ago.)

    Updating this plugin to use explicit values for every field when doing an INSERT will probably remedy my woes, and help future-proof the plugin from any other silliness some future MySQL-alike might have lurking.

    Plugin Author John Godley

    (@johnny5)

    Thanks, that’s great.

    It seems neither of the tables have the default value set for last_access.

    The thing that caught my eye is the title column – it’s set as VARCHAR(50). This is a column that was changed in version 3.0 to a TEXT column. Your database should have been altered as part of the internal database upgrade process.

    The fact that it isn’t makes me wonder if the last_access column is also somehow missing the default value as part of a missed upgrade.

    Are these tables ‘old’? I’ve not seen these specific problems occur elsewhere so I’m wondering if the problem may be specific to your table (if it was typical of all MariaDB installs I would expect to see more reports)

    If you have the time it would be interesting to see what the tables of a fresh Redirection installation looks like.

    Either way I can certainly be explicit when setting all columns.

    Thread Starter David E. Smith

    (@desmith)

    I’ve spot-checked several of the 85 sites we have using Redirection. In general, it looks like sites that we’ve had for a few years still have the ‘old’ schema, and younger sites have the new/correct schema, but I can’t immediately find a 100% verifiable pattern. If you updated the schema in 3.0, my wild guess would be that something (a previous schema change, maybe?) specific to older sites caused the schema update to fail.

    Based on the datestamps in this plugin’s change log, and our usual upgrade cycles, we probably went from 2.10.1, straight to 3.2. But that would have been for all of our sites, so that doesn’t immediately explain why the upgrade worked on most sites but not all. And no, I don’t have logs from February to explain the failure πŸ˜‰

    Wonder if it’d be worth adding a function that triggers on every plugin upgrade, that re-verifies (and corrects if necessary) the database layout?

    Thread Starter David E. Smith

    (@desmith)

    As I look things over, I think I may be conflating two separate issues, which we happened to discover at about the same time.

    The first issue is the one I originally reported, the one with the ‘regex’ column (on at least one site). That one, you’ve already said a bugfix is forthcoming, and thank you for that.

    The second one is how some sites didn’t evidently get their schemas upgraded properly. Since you already have code to handle upgrades, I wonder if it’d be worth doing a general checkup on things as part of every plugin update.

    (Another horrifying possibility that just occurred to me: When does the schema update normally trigger? Some of the sites where I’m seeing the old schema are test sites, where it’s entirely possible nobody has accessed them in a few months…)

    Plugin Author John Godley

    (@johnny5)

    The plugin’s status page does check the database, but only in a limited way. I don’t think this is a widespread issue, and reports of schema problems are very small. It’s usually easier just to fix the DB manually, or reset the plugin, than put a lot of effort into checking and fixing columns.

    I suspect the problems are caused by particular DB configurations, or user permissions, that result in an update being ignored. I don’t think it’s related to MariaDB itself as Redirection doesn’t do anything complicated.

    There will be a bunch of changes coming in future versions, and one of the main difficulties is upgrading the database in a way that doesn’t break anything. I’ll certainly be looking at this aspect again in more detail then, and will probably make it where an admin user has to action the upgrade.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Incorrect integer value ” for column ‘regex’ when creating new redir’ is closed to new replies.