Postgres numeric check needs to happen after precision check in schema generation

stormsweeper - July 17, 2009 - 19:28
Project:Drupal
Version:7.x-dev
Component:postgresql database
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review
Issue tags:PostgreSQL Surge
Description

The current function:

<?php
 
protected function createFieldSql($name, $spec) {
...
    if (!empty(
$spec['unsigned'])) {
     
$sql .= " CHECK ($name >= 0)";
    }

    if (!empty(
$spec['length'])) {
     
$sql .= '(' . $spec['length'] . ')';
    }
    elseif (isset(
$spec['precision']) && isset($spec['scale'])) {
     
$sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')';
    }

...
  }
?>

So what happens is if you define a schema element of type numeric with a precision and scale specified, and unsigned, you get this :

colname numeric CHECK (colname >= 0)(10, 2)

The patch switches these two so you get the expected result of

colname numeric(10, 2) CHECK (colname >= 0)

AttachmentSizeStatusTest resultOperations
pgsql-unsigned.D7.patch1.09 KBIdleFailed: Failed to install HEAD.View details | Re-test

#1

stormsweeper - July 17, 2009 - 19:31
Title:Postgres numeric check needs to happen after precision check» Postgres numeric check needs to happen after precision check in schema generation
Component:database system» postgresql database

Marking as postgres specific

#2

Damien Tournoud - July 17, 2009 - 23:33
Status:needs review» needs work

This type of things scream for a test. Would it be possible to extend the Schema API tests to include this case?

#3

stormsweeper - July 18, 2009 - 21:26

Let me see what tests are there now, although I don't think testbot uses Postgres.

#4

stormsweeper - July 18, 2009 - 22:58

Added a new test that creates a table with unsigned columns of each number type, and then tries to insert a negative value in all of them. The test is db agnostic.

AttachmentSizeStatusTest resultOperations
pgsql-unsigned-with-test.D7.patch3.36 KBIdleFailed: 11755 passes, 103 fails, 92 exceptionsView details | Re-test

#5

stormsweeper - July 18, 2009 - 23:12
Status:needs work» needs review

Now let's see if the test bot chokes on this.

#6

stormsweeper - July 18, 2009 - 23:48
Status:needs review» needs work

Not sure what I did, but it looks like the new test broke the Schema API test class so bad that it didn't load (see the detailed results). Will chew through this.

#7

Josh Waihi - July 31, 2009 - 02:24
Priority:normal» critical
Status:needs work» reviewed & tested by the community

forgot to call function as a method. fixed, this patch works, Thanks.

AttachmentSizeStatusTest resultOperations
522786-pgsql-unsigned-with-test.D7.patch3.35 KBIdlePassed: 14688 passes, 0 fails, 0 exceptionsView details | Re-test

#8

webchick - August 4, 2009 - 07:32
Status:reviewed & tested by the community» needs work

Couple of minor things with the test:

+   * Tests creating unsigned columns and that those columns reject
+   * negative values on insert.

Please rephrase so this fits within 80 chars.

+    // set up unsigned schema with just serial column

All comments should be written "With sentence capitalization, ending in a period." There are a few lines like this.

+      'fields' => array('serial_col' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE)),
...
+      $col_spec = array('type' => $type, 'unsigned'=> TRUE);
...
+   * @param $col
etc.

We don't abbreviate variable, etc. names. Please spell it out as "column".

#9

stormsweeper - August 7, 2009 - 01:56

Working on it now. Is there a compiled addendum anywhere for test coding standards over and above the standard Drupal ones?

#10

stormsweeper - August 7, 2009 - 02:51
Status:needs work» needs review

Lightly refactored the patch, which included catching a small bug with the inserts.

AttachmentSizeStatusTest resultOperations
522786-pgsql-unsigned-with-test.D7.patch3.53 KBIdleFailed: 12411 passes, 1 fail, 0 exceptionsView details | Re-test

#11

stormsweeper - August 7, 2009 - 03:23

Also, there's already a D6 version of this patch here: #256001: pgsql driver does not handle unsigned numeric fields

#12

stormsweeper - August 7, 2009 - 10:59

I missed the inline comments before.

AttachmentSizeStatusTest resultOperations
522786-pgsql-unsigned-with-test.D7.patch3.56 KBTest request sentFailed: Invalid PHP syntax in modules/simpletest/tests/schema.test.View details

#13

System Message - August 19, 2009 - 15:41
Status:needs review» needs work

The last submitted patch failed testing.

#14

stormsweeper - August 19, 2009 - 16:22

I'm going to wait a bit and set this back to CNR. The current HEAD of Drupal is broken, it seems.

#15

stormsweeper - August 19, 2009 - 19:53

OK, sorted out the update, but the same three asserts fail on a clean checkout of HEAD. They're all string comparisons, but as far as I can tell the text has not changed:

In modules/system/system.test, lines 118-122:

<?php
    $this
->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));

   
// Check that hook_modules_installed and hook_modules_enabled hooks were invoked and check tables.
   
$this->assertText(t('hook_modules_installed fired for aggregator'), t('hook_modules_installed fired.'));
   
$this->assertText(t('hook_modules_enabled fired for aggregator'), t('hook_modules_enabled fired.'));
?>

The module is enabled just fine, and every other assert passes. I'll check back tomorrow to set this to CNR, as I am certain the patch is not at fault.

#16

stormsweeper - August 20, 2009 - 23:11
Status:needs work» needs review

is testbot fixed now?

#17

stormsweeper - August 20, 2009 - 23:12

Oh, and I think this was the cause of the last fails: #554106: Module enable/disable tests failing on testing servers

#18

Gábor Hojtsy - September 14, 2009 - 10:42

Just marked #256001: pgsql driver does not handle unsigned numeric fields postponed on this one, since that is the same patch for Drupal 6.

#19

Josh Waihi - October 19, 2009 - 05:20
Status:needs review» reviewed & tested by the community

I like it. Lets get this in.

#20

System Message - October 29, 2009 - 18:10
Status:reviewed & tested by the community» needs work

The last submitted patch failed testing.

#21

stormsweeper - November 8, 2009 - 20:44
Status:needs work» needs review

It looks like another test failed before it got to the ones in here.

#22

System Message - November 16, 2009 - 04:47

Josh Waihi requested that failed test be re-tested.

 
 

Drupal is a registered trademark of Dries Buytaert.