OK. Understood.

But I must say it doesn't conform with web2py documentation.

About default, the book says: default sets the default value for the
field. The default value is used when performing an insert if a value
is not explicitly specified. It is also used to pre-populate forms
built from the table using SQLFORM.

Assuming default==update may be a source of confusion and unexpected
behaviour. I tried it today. I lost almost a day trying to figure it
out.
In spite of that, how can I have my example field filled with None
when inserted and just populated when updated?
Note that I'm running from shell because I intent to run this process
by a cron job. So, http requests are not present here.

About update, the book says: update contains the default value for
this field when the record is updated.

Well, again, assuming default==update is not what manual says.
When developing database applications, update is understood as an
event that occurs when something changes in your *existing* record (or
row, if purists read this.). So, assume default content is equal
update content may not be a good practice here, and, again, source of
confusion.

Another comment, if allowed, is about datetime.now() be evaluated just
when the table is defined. It is not explicit in book, too.
If I have a background process listening to some semaphores and
updating and inserting records through a cron job, it's worthless and,
again, my be a source of misunderstanding.


Massimo, I ask you to think about that and inform us if web2py way of
doing theses things will change or documentation will be updated to
reflect this behaviour.

--
Vinicius Assef.




On Mon, Nov 8, 2010 at 5:09 PM, mdipierro <[email protected]> wrote:
> no. if you have update but not default, default==update.
>
> On Nov 8, 1:02 pm, Vinicius Assef <[email protected]> wrote:
>> Thanks, Massimo.
>>
>> But, when the record is inserted, the field with "update" param
>> shouldn't be None?
>>
>> --
>> Vinicius Assef.
>>
>> On Mon, Nov 8, 2010 at 4:58 PM, mdipierro <[email protected]> wrote:
>> > This is misunderstanding. Yes what you have is correct.
>>
>> > The default=datetime.now() and update=datetime.now() is evaluated only
>> > ONCE when the table is defined therefore when you insert and update
>> > the values are always the same.
>>
>> > BUT
>>
>> > when the code is in a web2py controller, the model is run again at
>> > every http request and therefore the values of default and request
>> > will be updated.
>>
>> > Massimo
>>
>> > On Nov 8, 12:51 pm, Vinicius Assef <[email protected]> wrote:
>> >> Buddies, this is what is happening, step by step:
>>
>> >>http://pastebin.com/b14HLy39
>>
>> >> This test was made with latest stable version: Version 1.88.2
>> >> (2010-10-29 23:04:43)
>>
>> >> Again, am I missing something?
>>
>> >> I don't think there is a bug here. I expect I am making a really big
>> >> and stupid mistake.
>> >> This is too important to not be working out.
>>
>> >> By the way: I'm using Ubuntu 9.04.
>>
>> >> --
>> >> Vinicius Assef.
>>
>> >> On Mon, Nov 8, 2010 at 3:13 PM, Vinicius Assef <[email protected]> 
>> >> wrote:
>> >> > Massimo, I expect the correct way is:
>>
>> >> > a) When inserting (sql insert) a new record:
>> >> > 1) was_inserted_on receives request.now contents (this is ok)
>> >> > 2) was_updated_on receives null
>>
>> >> > b) When updating (sql update) a record:
>> >> > 1) was_inserted_on doesn't change is value (this is ok)
>> >> > 2) was_update_on receives request.now
>>
>> >> > What is happening here, with web2py 1.87.3 and SQLite:
>>
>> >> > a) When inserting (sql insert) a new record:
>> >> > 1) was_inserted_on receives request.now content
>> >> > 2) was_updated_on receives request.now content
>>
>> >> > b) When updating (sql update) a record:
>> >> > 1) was_inserted_on doesn't change its value
>> >> > 2) was_update_on doesn't change its value
>>
>> >> > Am I loosing something?
>>
>> >> > --
>> >> > Vinicius Assef.
>>
>> >> > On Mon, Nov 8, 2010 at 2:27 PM, mdipierro <[email protected]> 
>> >> > wrote:
>> >> >> What you expect is correct and I cannot reproduce the problem. how do
>> >> >> you update the record?
>>
>> >> >> On Nov 8, 8:54 am, Vinicius Assef <[email protected]> wrote:
>> >> >>> I have this model just for test:http://pastebin.com/vF4VBLLM
>>
>> >> >>> Field 'was_inserted_on' is working all right. It has default insert
>> >> >>> value and it isn't updated across record updates. It's ok.
>>
>> >> >>> But 'was_updated_on' is working the same way.
>>
>> >> >>> I imagined it was null when record is inserted and in every record
>> >> >>> update, it would be this column updated.
>>
>> >> >>> At least, it was what I got from we2bpy manual in Record
>> >> >>> Representation section (DAL chapter).
>>
>> >> >>> Where did I misunderstood?
>>
>> >> >>> By the way, I solved that using compute in was_updated_on field and
>> >> >>> returning request.now.
>>
>> >> >>> --
>> >> >>> Vinicius Assef.
>>
>>

Reply via email to