migrations icon indicating copy to clipboard operation
migrations copied to clipboard

Baking Seed with data from table with Date or Time results in FrozenDate/FrozenTime instead of string

Open challgren opened this issue 2 years ago • 0 comments

This is a (multiple allowed):

  • [x] bug

  • [ ] enhancement

  • [ ] feature-discussion (RFC)

  • CakePHP Version: 4.4.2

  • Migrations plugin version: 3.5.2

  • Bake plugin version (if relevant): 2.7.0

  • Database server (MySQL, SQLite, Postgres): MariaDB Docker 10.6.8

  • PHP Version: PHP 8.1.8

  • Platform / OS: Docker FROM php:8.1-apache-bullseye

What you did

Baked a seed using bin/cake bake seed --data --table product_data ProductDataDemo then cleared the table out and ran bin/cake migrations seed --seed ProductDataDemoSeed and encountered

2022-07-25 23:48:06 error: [Error] Object of class DateTimeImmutable could not be converted to string in /var/www/html/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php on line 335

When inspecting the seed that was generated by the bake command, I observe that instead of dumping a string it dumps a FrozenDate/FrozenTime that can't be seeded since DateTimeImmutable cannot be converted to a string during seed insertion.

Table schema

CREATE TABLE `product_data` (
  `datapoint1` varchar(32) DEFAULT NULL,
  `datapoint2` varchar(32) DEFAULT NULL,
  `sku` varchar(16) DEFAULT NULL,
  `pallet_id` varchar(64) DEFAULT NULL,
  `carton_id` varchar(64) DEFAULT NULL,
  `dc_name` varchar(255) DEFAULT NULL,
  `dc_ship_to_company` varchar(255) DEFAULT NULL,
  `dc_ship_to_country` varchar(4) DEFAULT NULL,
  `dc_sold_to_company` varchar(255) DEFAULT NULL,
  `dc_sold_to_country` varchar(4) DEFAULT NULL,
  `dc_ship_date` date DEFAULT NULL,
  `t1_reporting_partner_name` varchar(255) DEFAULT NULL,
  `t1_reporting_country` varchar(4) DEFAULT NULL,
  `t1_sold_to_customer_name` varchar(255) DEFAULT NULL,
  `t1_sold_to_country` varchar(4) DEFAULT NULL,
  `t1_ship_to_customer_name` varchar(255) DEFAULT NULL,
  `t1_ship_to_country` varchar(4) DEFAULT NULL,
  `t1_sold_date` date DEFAULT NULL,
  `label_insert_time` datetime DEFAULT NULL,
  `mfg_insert_time` datetime DEFAULT NULL,
  `dc_insert_time` datetime DEFAULT NULL,
  `t1_insert_time` datetime DEFAULT NULL,
  UNIQUE KEY `product` (`datapoint1`,`datapoint2`,`pallet_id`,`carton_id`),
  KEY `serial_number` (`datapoint1`),
  KEY `qr_code` (`datapoint2`),
  KEY `carton_id` (`carton_id`),
  KEY `pallet_id` (`pallet_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Table data

INSERT INTO product_data (datapoint1,datapoint2,sku,pallet_id,carton_id,dc_name,dc_ship_to_company,dc_ship_to_country,dc_sold_to_company,dc_sold_to_country,dc_ship_date,t1_reporting_partner_name,t1_reporting_country,t1_sold_to_customer_name,t1_sold_to_country,t1_ship_to_customer_name,t1_ship_to_country,t1_sold_date,label_insert_time,mfg_insert_time,dc_insert_time,t1_insert_time) VALUES ('100311709337', '11750055387', NULL, 'Label Set 1', NULL, 'XPO Sandston', 'Printing Mexico', NULL, 'Computing and Printing Mexico', 'MX', '2020-05-07', 'Ingram Micro Mexico', NULL, 'Manhattan Products', 'MX', 'Manhattan Products', 'MX', '2020-06-08', '2019-02-13 00:14:28', NULL, NULL, NULL);

Expected Behavior

Seed baked with the following $data array

        $data = [
            [
                'datapoint1' => '100311709337',
                'datapoint2' => '11750055387',
                'sku' => NULL,
                'pallet_id' => 'Label Set 1',
                'carton_id' => NULL,
                'dc_name' => 'XPO Sandston',
                'dc_ship_to_company' => 'Printing Mexico',
                'dc_ship_to_country' => NULL,
                'dc_sold_to_company' => 'Computing and Printing Mexico',
                'dc_sold_to_country' => 'MX',
                'dc_ship_date' => '2020-05-07',
                't1_reporting_partner_name' => 'Ingram Micro Mexico',
                't1_reporting_country' => NULL,
                't1_sold_to_customer_name' => 'Manhattan Products',
                't1_sold_to_country' => 'MX',
                't1_ship_to_customer_name' => 'Manhattan Products',
                't1_ship_to_country' => 'MX',
                't1_sold_date' => '2020-06-08',
                'label_insert_time' => '2019-02-13 00:14:28',
                'mfg_insert_time' => NULL,
                'dc_insert_time' => NULL,
                't1_insert_time' => NULL,
            ],

Actual Behavior

Seed baked with classes in time/date fields

$data = [
            [
                'datapoint1' => '100311709337',
                'datapoint2' => '11750055387',
                'sku' => NULL,
                'pallet_id' => 'Label Set 1',
                'carton_id' => NULL,
                'dc_name' => 'XPO Sandston',
                'dc_ship_to_company' => 'Printing Mexico',
                'dc_ship_to_country' => NULL,
                'dc_sold_to_company' => 'Computing and Printing Mexico',
                'dc_sold_to_country' => 'MX',
                'dc_ship_date' => 
                Cake\I18n\FrozenDate::__set_state(array(
                'date' => '2020-05-07 00:00:00.000000',
                'timezone_type' => 3,
                'timezone' => 'UTC',
                )),
                't1_reporting_partner_name' => 'Ingram Micro Mexico',
                't1_reporting_country' => NULL,
                't1_sold_to_customer_name' => 'Manhattan Products',
                't1_sold_to_country' => 'MX',
                't1_ship_to_customer_name' => 'Manhattan Products',
                't1_ship_to_country' => 'MX',
                't1_sold_date' => 
                Cake\I18n\FrozenDate::__set_state(array(
                'date' => '2020-06-08 00:00:00.000000',
                'timezone_type' => 3,
                'timezone' => 'UTC',
                )),
                'label_insert_time' => 
                Cake\I18n\FrozenTime::__set_state(array(
                'date' => '2019-02-13 00:14:28.000000',
                'timezone_type' => 3,
                'timezone' => 'UTC',
                )),
                'mfg_insert_time' => NULL,
                'dc_insert_time' => NULL,
                't1_insert_time' => NULL,
            ],

challgren avatar Jul 26 '22 00:07 challgren