Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dalin’s picture

Status: Active » Needs review
Issue tags: +Schema API
FileSize
1.32 KB

I believe this just needs a few isset($info['type']), but I'm not familiar enough with cross-db data types to know for sure.

Crell’s picture

Status: Needs review » Needs work

IMO we should look into why $info['type'] doesn't exist in the first place. I'd consider that a deeper bug. Really, isset() is a bad way to respond to undefined variables in a definition array. :-) Proper defaults are the right way.

dalin’s picture

@crell most of the time I would agree with you. However I should have elaborated, this happens when you have a field something like this:

      'birthdate' => array(
        'description' => "YYYY-MM-DD formatted birth date.",
        'mysql_type' => 'DATE',
        'pgsql_type' => 'timestamp without time zone',
        'not null' => FALSE,
      ),

As I understand it, it isn't possible to come up with a value for 'type' in this case.

Damien Tournoud’s picture

I would just add a NULL 'type' in _drupal_schema_initialize().

jbrown’s picture

The 'type' key is not optional.

Damien Tournoud’s picture

@jbrown: yes, it is.

dalin’s picture

Status: Needs work » Needs review
FileSize
692 bytes

Added a NULL 'type' in _drupal_schema_initialize().

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

agree with the fix.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This needs tests.

Vacilando’s picture

Ran into the same problem, found this issue, applied dalin's patch from #7 and the notices disappeared.

j4’s picture

works for me too..

Jaya

naringas’s picture

Had this problem in 7.10 using my custom module code (which also has a schema like #998632-3: drupal_write_record() throws PHP notices if any fields use DB-specific data types).
I applied patch in my development server and it fixed the issue (after a cache flush).

Vacilando’s picture

Bump. The patch in #7 has worked for me again, on a different system, in D7.14.

cjoy’s picture

patch in #7 worked fine on 7.15, no more notices caused by the following schema field:

'createtime'                 => array(
        'description' => 'timestamp',
        'mysql_type'  => 'timestamp',
        'not null'    => FALSE,
      )
tonylegrone’s picture

Adding a NULL type to hook_schema also fixed this bug for me without applying the patch.

      'valid_from' => array(
        'description' => 'The start date.',
        'type' => NULL,
        'mysql_type' => 'datetime',
      ),
poker10’s picture

This is a bit old, but according to the schema documentation (https://www.drupal.org/docs/7/api/schema-api/schema-reference):

All parameters apart from 'type' are optional except that type 'numeric' columns must specify 'precision' and 'scale', and 'varchar' columns must specify 'length'.

According to this I think that it would probably be sufficient to update the schema documentation page to include an information, that if someone uses a DB-specific type, it is also needed to put a NULL to the type parameter (like it was mentioned in #15).

If we want to go the other way and add a "safety net" (see #7), then I have created a test for this. Reuploading the original patch (with slightly modified comment) with the test added. We will discuss which approach will be better in D7.

Just a note, _drupal_schema_initialize() was removed in D10, so we can proceed independently with this D7 issue.

mcdruid’s picture

I think this looks good.

Here's a test-only patch.. I'll also re-upload the full patch from #16 so we can have the most recent patch passing.

The last submitted patch, 17: 998632-17_test_only.patch, failed testing. View results

mcdruid’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +RTBM

I'm happy to RTBC (/ RTBM) this as my last patch was just splitting out the tests to show that they fail in isolation.

  • poker10 committed 5a129b18 on 7.x
    Issue #998632 by dalin, poker10: drupal_write_record() throws PHP...
poker10’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -RTBM

Committed, thanks everyone!

Status: Fixed » Closed (fixed)

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