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

NOW() not recognized as now() #18

Closed
dargueta opened this issue Jul 12, 2021 · 3 comments
Closed

NOW() not recognized as now() #18

dargueta opened this issue Jul 12, 2021 · 3 comments

Comments

@dargueta
Copy link

dargueta commented Jul 12, 2021

Describe the bug

NOW() is not recognized as equivalent to now() when used as a default value, even though SQL is case-insensitive.

To Reproduce

Given the following SQL:

ddl = """
CREATE TABLE asdf (
  t TIMESTAMP DEFAULT NOW()
);
"""
print(omymodels.create_models(ddl=ddl, models_type="dataclass")["code"])

The output is

import datetime
from dataclasses import dataclass


@dataclass
class Asdf:

    t: datetime.datetime = 'NOW()'  # Default value is wrong

Note that, while the datatype of the column is correct, the default value is a string instead of a call to datetime.datetime.now(). If we make NOW()` lowercase, we get the expected output.

import datetime
from dataclasses import dataclass


@dataclass
class Asdf:

    t: datetime.datetime = datetime.datetime.now()

n.b. the expected output has a bug in it which I'll file a separate ticket for

Expected behavior

SQL is case-insensitive, therefore now() and NOW() should behave identically and produce the same output.

Additional context

Python: 3.8.2
Version: 0.8.1

@xnuinside
Copy link
Owner

@dargueta thanks for the report, I will fix it as soon as possible

@xnuinside
Copy link
Owner

@dargueta
Copy link
Author

Thanks!

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

2 participants