[CONPY-150] Error when fetching results from a DATETIME with value NULL Created: 2021-04-06  Updated: 2021-08-20  Resolved: 2021-04-06

Status: Closed
Project: MariaDB Connector/Python
Component/s: DBAPI 2.0
Affects Version/s: 1.0.6
Fix Version/s: 1.0.7

Type: Bug Priority: Major
Reporter: Kiusa Diakusen Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None
Environment:

ubuntu 20.04
python latest
mariadb server latest



 Description   

Hello,

I have a quite obvious bug to report:

I have a table row that looks like this:
id title category date_posted date_due content file user_id
6 test 7 10 2021-04-01 21:50:21 content 7 strawsf9cdaf.txt 16

The problem is that i have a DATETIME field that is NULL (the date_due date is not mandatory in my app)

It seems that after passing values to the execute() method, the fetchall() method parses returned data differently.

First case works great Second returns the "ValueError: year 0 is out of range"

id=("6",)
statement1 = "select * from posts where id = 6"
statement2 = "select * from posts where id = ?"
 
db.cursor.execute(statement1)
result = db.cursor.fetchall()
for x in result:
     print(x)
 
db.cursor.execute(statement2, id)
result = db.cursor.fetchall()
for x in result:
     print(x)

I tried to list() the connector - same result

I tried to change values and table column attributes - same result

I though its a problem of versions so i updated to latest python, mariadb server and python connector (on ubuntu 20.04)- same result

The result:

6, 'test 7', 10, datetime.datetime(2021, 4, 1, 21, 50, 21), None, 'content 7', 'strawsf9cdaf.txt', 16)
ValueError: year 0 is out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/project dir/main_test3.py", line 38, in <module>
result = db.cursor.fetchall()
SystemError: <method 'fetchall' of 'mariadb.connection.cursor' objects> returned a result with an error set

Process finished with exit code 1

I posted the issue for easy reading also to stackoverflow:
https://stackoverflow.com/questions/66963588/python-mariadb-connector-error-when-fetching-results-from-a-datetime-with-value



 Comments   
Comment by Kiusa Diakusen [ 2021-04-06 ]

Tried this with the mysql connector and seems to work fine on the same database so i guess the problem is in the mariadb connector

Comment by Georg Richter [ 2021-04-06 ]

Could you please also attach the sql definition of the table posts and provide the version of MariaDB server.

Thanks!

Comment by Kiusa Diakusen [ 2021-04-06 ]

Hello Georg,

tried with null, not null and with or default value
also tried dif charsets
same result

CREATE TABLE `posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`category` int(11) NOT NULL,
`date_posted` datetime NOT NULL DEFAULT current_timestamp(),
`date_due` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`content` text NOT NULL,
`file` varchar(70) DEFAULT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `posts_fk_users` (`user_id`),
KEY `posts_fk_categories` (`category`),
CONSTRAINT `posts_fk_categories` FOREIGN KEY (`category`) REFERENCES `categories` (`id`),
CONSTRAINT `posts_fk_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 |

Comment by Kiusa Diakusen [ 2021-04-06 ]

Ooops i forgot

mariadb --version
mariadb Ver 15.1 Distrib 10.3.25-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Comment by Georg Richter [ 2021-04-06 ]

fixed in rev. 6e50bfcbe5c485937b152c516ce94e426229ca72

Comment by Kiusa Diakusen [ 2021-04-06 ]

Thank you, Georg!
Is there a way to update my current connector or i better wait for the new version?
Thank you again

Comment by Georg Richter [ 2021-04-06 ]

You can download the sources from Github and build the package with python setup.py build and python setup.py install.

Comment by Kiusa Diakusen [ 2021-04-06 ]

Thank you very much!

Generated at Thu Feb 08 03:30:37 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.