Good catch. Yet, default values are not validated (for speed reasons)
unless they go through a form.
On Wednesday, 12 December 2012 21:34:12 UTC-6, David Tucker wrote:
>
> Finally, I figured out the issue! In order to store a time() from epoch,
> your db type cannot be 'time' but instead must be 'float'
> The crud.create form I was generating let the erroneous value thru, and
> the db wasn't liking it; however, the form within appadmin caught the issue
> saying it needed hh:mm:ss. I imagine what happened was I set the default
> value for the field to time() and the type to 'time' and it tried to unpack
> a datetime.time from the float only finding 2 values (left & right of
> decimal). In my prior post, the default value was 0, hence need more than 1
> value to unpack. not sure this is relevant to the originally posted
> problem, but hopefully it'll help someone in the future.
>
> what a noob...
>
>
> On Wednesday, December 12, 2012 12:57:35 PM UTC-8, David Tucker wrote:
>>
>> I've narrowed down the problem. I dropped the table then added it again
>> and started removing fields and doing the create. My problem is a field
>> called 'expiration' that I want to set automatically for the user. My model
>> includes 3 tables: tiers, groups, and accounts. Each account references the
>> group it's in (every account is in a group), and each group references a
>> tier. When an account is created, I want the expiration field of the
>> account to be:
>>
>> (time since epoch in seconds)+(the new account's assigned group's tier's
>> TTL [days] in seconds) which I have tried to achieve like so:
>>
>>
>> Field('expiration', 'time',
>>
>> required=True,
>>
>> notnull=True,
>>
>> default=time(),
>>
>> writable=False,
>>
>> represent=lambda expiration, row:
>> datetime.datetime.fromtimestamp(int(expiration)),
>>
>> compute=lambda row: time()+row.batch.tier.ttl*24*60*60)
>>
>>
>> note that row.batch is the account's reference to a group (but it can't
>> be called group since that is a reserved word)
>>
>> This produced problems with compute, so I circumvented by commenting it
>> out and adding this to the creation/insert controller:
>>
>>
>> group = __get_group()
>>
>> db.accounts.batch.default = group.id
>>
>> db.accounts.expiration.default = time()+(group.tier.ttl*24*60*60)
>>
>> form = crud.create(db.accounts, message='Account Created', next=URL(
>> 'accounts','review')+'/[id]')
>>
>>
>> I am missing something... because now i'm getting:
>> <type 'exceptions.ValueError'> need more than 2 values to unpack
>>
>> ...stumped.
>>
>>
>> On Wednesday, December 12, 2012 12:18:58 PM UTC-8, David Tucker wrote:
>>>
>>> I am having a similar problem. I did an insert using crud.create and it
>>> went through, but now I get the error described above whenever I do
>>> anything related to tht table... I tried this, but my notnull constraint
>>> got in the way so I tried:
>>>
>>> db(db.youtable.id>0).update(thedatetimefield=datetime.datetime.utcnow())
>>>
>>> and now I'm getting this traceback:
>>>
>>> Traceback (most recent call last):
>>> File "gluon/main.py", line 564, in wsgibase
>>> File "gluon/dal.py", line 529, in close_all_instances
>>> File "gluon/dal.py", line 509, in close
>>> File "gluon/dal.py", line 1652, in commit
>>> OperationalError: SQL logic error or missing database
>>>
>>>
>>> Any idea what's going on?
>>>
>>>
>>> On Sunday, April 5, 2009 10:01:13 PM UTC-7, mdipierro wrote:
>>>>
>>>> Let me guess... you changed a field from 'string' to 'datetime' using
>>>> sqlite? sqlite does not enforces field types hence it let you do the
>>>> migration even if there was data in there that is not of type
>>>> 'datetime'. You need to clean up that column.
>>>>
>>>> In your model do this
>>>>
>>>> db(db.youtable.id>0).update(thedatetimefield=None)
>>>>
>>>> run appadmin once than remove the above line.
>>>>
>>>> Massimo
>>>>
>>>>
>>>>
>>>> On Apr 5, 9:10 pm, "web2py <<<at>>> technicalbloke.com"
>>>> <[email protected]> wrote:
>>>> > Hi,
>>>> >
>>>> > Somehow (don't ask me how!) I've managed to bork my database :-/
>>>> > Appadmin let's me see all my tables except one, when I click on it's
>>>> > name it spews the message below. I don't care about the data inside,
>>>> > I'd just like to have my database rebuilt from the model so what's
>>>> the
>>>> > best way to do that?
>>>> >
>>>> > db.my_table.truncate?
>>>> > db.my_table.drop?
>>>> > delete the contents of the 'databases' folder?
>>>> >
>>>> > Traceback (most recent call last):
>>>> > File "/rahrahrah/web2py/gluon/restricted.py", line 98, in
>>>> restricted
>>>> > exec ccode in environment
>>>> > File "/rahrahrah/web2py/applications/tcrm/views/appadmin.html",
>>>> line
>>>> > 102, in <module>
>>>> > File "/rahrahrah/web2py/gluon/sqlhtml.py", line 605, in __init__
>>>> > for (rc, record) in enumerate(sqlrows):
>>>> > File "/rahrahrah/web2py/gluon/sql.py", line 2127, in __iter__
>>>> > yield self[i]
>>>> > File "/rahrahrah/web2py/gluon/sql.py", line 2082, in __getitem__
>>>> > str(value)[:10].strip().split('-')]
>>>> > ValueError: need more than 1 value to unpack
>>>> >
>>>> > Cheers,
>>>> >
>>>> > Roger.
>>>
>>>
--