laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.22k stars 10.91k forks source link

Job Queue Datetime bug when using the MariaDB Database driver #50542

Closed apoorvpal01 closed 6 months ago

apoorvpal01 commented 6 months ago

Laravel Version

11.0.5

PHP Version

8.3.3

Database Driver & Version

MariaDB 10.11.2 on Ubuntu 22.04 LTS with the MariaDB driver

Description

SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1710393058' for columnlaravel_test.jobs.available_atat row 1

I get the error mentioned above when running jobs on the PHP 8.3.3. The database I use has not been changed from the one migrated via Laravel 7 with the MySQL driver.

Column DataType Null Default
reserved_at timestamp YES NULL
available_at timestamp NO 0000-00-00 00:00:00
created_at timestamp NO current_timestamp()

Steps To Reproduce

staudenmeir commented 6 months ago

Hi @apoorvpal01,

Upgrade sequentially to Laravel 11

Did you upgrade from Laravel 7 to Laravel 11 just now or have you been running Laravel 10 for a while?

Can you switch back to the mysql driver temporarily and test if the job works?

apoorvpal01 commented 6 months ago

Hi @staudenmeir

I have been running on Laravel 10 for the past year without any issues, with the same config (except the DB driver change)

I switched back to the mysql driver on Laravel 11 and it worked fine. The problem occurs only on the mariadb driver.

driesvints commented 6 months ago

cc @hafezdivandari

hafezdivandari commented 6 months ago

@apoorvpal01 It's maybe related to strict mode, can you try mariadb driver with strict => false?

apoorvpal01 commented 6 months ago

@hafezdivandari You're right. Disabling the strict mode fixed it. If this is the default requirement for queues, is it in the docs somewhere? Did I miss it? If not, maybe I could add a PR for this to be included in the docs for jobs.

hafezdivandari commented 6 months ago

@apoorvpal01 actually it's not about strict mode. The problem is that you're using an incompatible jobs table structure, the available_at column is not a timestamp but unsignedInteger (even in Laravel 7).

Laravel 7: https://github.com/laravel/framework/blob/7.x/src/Illuminate/Queue/Console/stubs/jobs.stub#L21-L23

Laravel 11: https://github.com/laravel/framework/blob/11.x/src/Illuminate/Queue/Console/stubs/jobs.stub#L19-L21

staudenmeir commented 6 months ago

(The disabled strict mode just hid the error from you all this time.)

As @hafezdivandari said, it seems like Laravel has always being using integer columns for this table and therefore tries to insert a UNIX timestamp (instead of a datetime string).

apoorvpal01 commented 6 months ago

Oh, thanks for the clarification. I am not sure how I got this schema on the database then. I'll check that out. Sorry for the trouble, and thanks for your help!