Ticket #1716 (closed defect: worksforme)

Opened 14 months ago

Last modified 12 months ago

timestampable fields fail validation when data is loaded via fixtures

Reported by: hal Owned by: jwage
Priority: blocker Milestone: 1.0.5
Component: Validators Version: 1.0.4
Severity: Keywords:
Cc: Has Test: no
Status: Pending Core Response Has Patch: no

Description

When validation is enabled, (Doctrine::ATTR_VALIDATE => Doctrine::VALIDATE_ALL), timestampable fields fail validation when data is loaded via a fixture file.

This may have something to do with ticket #908, but hopefully a workaround can be found bearing in mind that fixtures are essential for testing, so validators cannot be used while this issue exists.

Change History

Changed 14 months ago by hal

To replicate this problem, use the following config...

config/doctrine/TestCountry.yml

TestCountry:
  tableName: test_country
  actAs:
    Timestampable:
      created:
        name: created_at
        type: timestamp
        format: Y-m-d H:i:s
        options:
          notnull: true
      updated:
        name: updated_at
        type: timestamp
        format: Y-m-d H:i:s
        options:
          notnull: true
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    name:
      type: string(2)
      fixed: true
      notnull: true

data/fixtures/TestCountry.yml:

TestCountry:
  country_1:
    name: gb

Changed 14 months ago by hal

BTW, the error returned is as follows:

"validation error in class TestCountry?"

Changed 14 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [5250]) [1.0, 1.1] Fixes issue with preInsert() and preUpdate() hooks being called after isValid() (fixes #1716)

Changed 13 months ago by enrico

  • status changed from closed to reopened
  • resolution fixed deleted

The same error occurs if you have additional timestamp fields:

TestCountry:
  tableName: test_country
  actAs:
    Timestampable: ~
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    name:
      type: string(2)
      fixed: true
      notnull: true
   testtime:
      type: timestamp

Changed 13 months ago by jwage

  • status changed from reopened to closed
  • resolution set to worksforme

Works for me with the following in the 1.0 sandbox:

Turned on validation:

Doctrine_Manager::getInstance()->setAttribute('validate', 'all');

Schema

TestCountry:
  tableName: test_country
  actAs:
    Timestampable:
      created:
        name: created_at
        type: timestamp
        format: Y-m-d H:i:s
        options:
          notnull: true
      updated:
        name: updated_at
        type: timestamp
        format: Y-m-d H:i:s
        options:
          notnull: true
  columns:
    id:
      type: integer
      primary: true
      autoincrement: true
    name:
      type: string(2)
      fixed: true
      notnull: true
    testtime:
      type: timestamp

Fixtures

TestCountry:
  country_1:
    name: gb
    testtime: '2008-09-01'

And run the following command:

./doctrine build-all-reload

Changed 13 months ago by enrico

  • status changed from closed to reopened
  • resolution worksforme deleted

What kind of database you're using? MySQL for example understand unix timestamps whereas PostgreSQL don't.

It would be interesting how the generated query looks like.

In my opinion the "Timestampable" timestamp fields will be filled with e.g. 2008-07-07 whereas the "normal" timestamp column will filled with an unix timestamp (seconds from 1970 etc).

Changed 13 months ago by jwage

  • status changed from reopened to closed
  • resolution set to worksforme

The generated query inserts the formatted date, not a unix timestamp. You need to make sure in your data fixtures that the date value is wrapped in single quotes as well.

Changed 12 months ago by enrico

Ok, thank you.

Note: See TracTickets for help on using tickets.