Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datetime '0000-00-00' maps to None #39

Closed
rodrigovalin opened this issue Nov 21, 2013 · 2 comments
Closed

Datetime '0000-00-00' maps to None #39

rodrigovalin opened this issue Nov 21, 2013 · 2 comments
Assignees
Milestone

Comments

@rodrigovalin
Copy link

The issue here is that both NULL datetimes and '0000-00-00' datetimes in the context of MySQL have the same meaning in the context of MySQLdb (both are represented as None) thus data will be lost in case of (as an example) data being copied from one data base to another.

I'm not seeing a solution here - yet -, as you can't have a Datetime object with day, month and year as 0 values.

My solution, for my specific problem is this (using MySQLdb-1.2.4, installed with pip), on times.py (line 79):

def Date_or_None(s):
    if s[0:4] == '0000': # this is my solution
        return s
    try: return date(*[ int(x) for x in s.split('-',2)])
    except: return None

So I'm returning the original Datetime representation string (lines 2 and 3 of code block were added by me).

@farcepest
Copy link
Owner

It's by design (obviously), but I am considering returning MySQL date values which cannot be turned into Python dates as the original string value, for version 1.3.

@ghost ghost assigned farcepest Nov 21, 2013
@saaj
Copy link

saaj commented Oct 28, 2014

I guess introducing backward-incompatible changes in minor version is generally a bad idea. Not only it may break a lot of code out there (which will be hard-to-debug as no string was expected). But also it'll make date values more inconsistent. Now it's clear that either you get datetime.datetime or NoneType for a date column value. So I think it's a special enough case for a developer who absolutely needs this quirky zero values, to either cast columns in the query to CHAR directly, or to redefine MySQLdb converters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants