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

get_model_for_table returns model which can not return create table SQL #213

Open
nnseva opened this issue Aug 29, 2024 · 0 comments
Open

Comments

@nnseva
Copy link

nnseva commented Aug 29, 2024

I supposed that the following code should get create table SQL into the s2 variable, but it raises the exception instead.

In [1]: from infi import clickhouse_orm as orm
In [2]: from utils.chdb import chdb
In [3]: db = chdb()
In [4]: class TestModel(orm.Model):
   ...:     source = orm.StringField()
   ...:     created_at_date = orm.DateField(default=orm.F.today())
   ...:     engine = orm.MergeTree(partition_key=('created_at_date',),order_by=('source',))
   ...: 
In [5]: db.create_table(TestModel)
In [6]: s1 = TestModel.create_table_sql(db)
In [7]: TestModelAdHoc = db.get_model_for_table(TestModel.table_name())
In [8]: s2 = TestModelAdHoc.create_table_sql(db)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[8], line 1
----> 1 s2 = TestModelAdHoc.create_table_sql(db)

File ~/py.3.11.transitflow/lib/python3.11/site-packages/infi/clickhouse_orm/models.py:369, in Model.create_table_sql(cls, db)
    367 # Engine
    368 parts.append(')')
--> 369 parts.append('ENGINE = ' + cls.engine.create_table_sql(db))
    370 return '\n'.join(parts)

AttributeError: 'NoneType' object has no attribute 'create_table_sql'

A reason probably that the get_model_for_table() method doesn't analize and store the table engine definition in the returned AdHoc model.

[remark for the sample code: the chdb() call returns the current Database instance]

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

1 participant