Open tripleee opened 8 years ago
I originally submitted a Bottle wishlist bug here; sorry for the mess.
Repro steps.
bash$ sqlite3 temp.db
sqlite> create table example(
...> id integer primary key,
...> timestamp datetime default CURRENT_TIMESTAMP
...> );
sqlite> insert into example (id) values (1);
sqlite> select * from example;
1|2016-06-09 08:31:11
So far so good. CURRENT_TIMESTAMP
gets substituted.
bash$ python
>>> import macaron
>>> class Example(macaron.Model): pass
...
>>> macaron.macaronage(dbfile='temp.db')
>>> flawed = Example.create()
>>> macaron.bake()
>>> [x.timestamp for x in Example.all()]
[u'2016-06-09 08:31:11', u'CURRENT_TIMESTAMP']
A workaround is to define a before_create
method in the Example
class which populates self.timestamp
with a suitable timestamp if it is None
; but this obviously defeats the purpose of having SQlite supply a default.
Macaron inserts the literal string
CURRENT_TIMESTAMP
if I declare a table with a field like this;and create a new
Example()
with no explicittimestamp
value.