[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-19 Thread Anthony
On Thursday, July 19, 2018 at 11:25:28 AM UTC-4, Lisandro wrote:
>
> That was my first thought: in some cases, another request deletes the 
> record right in the instant between the execution of the first and second 
> line.
> But I thought it wasn't possible because the function runs inside a db 
> transaction. Or could it still happen?
>

Well, I guess since the record is updated via .update_record, it should 
remain locked until the transaction is complete (depending on the database).
 

> Another thought is that the row.id is removed or set to None by 
> row.update_record(**data), so the next line would set row to None, thus 
> triggering the error.
>

Or the update changes the "id" of the original record. But according to the 
code of .update_record, neither of those things can happen (not even in 
web2py 2.10), as the "id" field is explicitly excluded from being updated 
either in the database or in the Row object itself.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-19 Thread Lisandro
Thanks Leonel.
I'm using PostgreSQL, so if that case isn't possible, then I think the 
problem could be in the second line, where the code retrieves the record 
using row.id:

row.update_record(**data)
row = db.content[row.id]  # the problem could be here
row.update_tsv()


Remember yesterday I realised the error is happening only in the apps 
running with the code above, and the error is in the third line (where 
apparently row is None). 
If I'm not wrong, that would mean the record wasn't retrieved. But as we 
know, the record exists (the previous line was executed successfully), so 
maybe row.id is None, therefor row ends up being None and causing the error 
at the third line. I can't say how could row.id end up being None, but I 
think that would be the problem here. I've just checked the code to see if 
the "id" field is updated or changed, but I didn't find anything regarding 
that. 

Anyway, in the next days I'll remove the fix to let only this code running:

row.update_record(**data)
row.update_tsv()

I think that is the proper and expected way.
If something goes wrong with that, I'll update this thread.

Once again I deeply thank you for your time and willingness to help!


P.S.: for the second time, I searched for a way to donate to web2py, but 
I've seen a post where you explain why you don't accept donations, so I'll 
try to contribute a bit more in the forum. What I have to offer is 
meaningless compared to what you bring to the forum, but I'll do my best.

El jueves, 19 de julio de 2018, 12:57:11 (UTC-3), Leonel Câmara escribió:
>
> It should not be possible if your database has proper transactions like 
> postgresql. If you're using something like mongodb then you're SOL.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-19 Thread Leonel Câmara
It should not be possible if your database has proper transactions like 
postgresql. If you're using something like mongodb then you're SOL.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-19 Thread Lisandro
That was my first thought: in some cases, another request deletes the 
record right in the instant between the execution of the first and second 
line.
But I thought it wasn't possible because the function runs inside a db 
transaction. Or could it still happen? 

Another thought is that the row.id is removed or set to None by 
row.update_record(**data), so the next line would set row to None, thus 
triggering the error.
But I'm not sure how could that happen. I checked and the "data" dictionary 
hasn't got the "id" key (I mean, the id field isn't updated).

Anyway, what I'm going to do to catch the error is this:

row.update_record(**data)
if not row:
return response.json({'success':False})
row.update_tsv()

This way I'll avoid the error ticket for those few cases.
I guess I could also decompile a couple of apps and put a log line there, 
though I don't know exactly what to log.



El jueves, 19 de julio de 2018, 10:56:55 (UTC-3), Anthony escribió:
>
> On Thursday, July 19, 2018 at 4:26:09 AM UTC-4, Lisandro wrote:
>>
>> Well, I owe you an apology, because I got confused regarding which app 
>> was throwing the error and which web2py version was running. 
>>
>> Until recently, I was using a very old web2py version (2.10). This 
>> problem was happening since long time ago (but not very frequently as I 
>> stated). For that old web2py version, I had already applied the fix to my 
>> app:
>>
>> row.update_record(**data)
>> row = db.content[row.id]
>> row.update_tsv()
>>
>
> There must still be something else going on that we're not seeing. Even in 
> web2py 2.10, there would have been no way to get the error in question, as 
> the .update_record method could not turn a Row object into None.
>
> I suppose the above code could generate this error if the record in 
> question could be deleted in a separate HTTP request in between the 
> execution of the first and second lines above. Is that possible (i.e., is 
> there some other action that could be deleting existing records)?
>
> Anthony
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-19 Thread Anthony
On Thursday, July 19, 2018 at 4:26:09 AM UTC-4, Lisandro wrote:
>
> Well, I owe you an apology, because I got confused regarding which app was 
> throwing the error and which web2py version was running. 
>
> Until recently, I was using a very old web2py version (2.10). This problem 
> was happening since long time ago (but not very frequently as I stated). 
> For that old web2py version, I had already applied the fix to my app:
>
> row.update_record(**data)
> row = db.content[row.id]
> row.update_tsv()
>

There must still be something else going on that we're not seeing. Even in 
web2py 2.10, there would have been no way to get the error in question, as 
the .update_record method could not turn a Row object into None.

I suppose the above code could generate this error if the record in 
question could be deleted in a separate HTTP request in between the 
execution of the first and second lines above. Is that possible (i.e., is 
there some other action that could be deleting existing records)?

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-17 Thread Dave S


On Tuesday, July 17, 2018 at 4:50:02 PM UTC-7, Leonel Câmara wrote:
>
> I have to say I'm completely stumped. I don't see how this is even 
> possible. Are you sure Line 301 is really the line after update_record?
>

That should be verifiable with the full ticket, not just the stack trace.
The ticket should have a code clip  to show the context of the line; 
the usual frame expansions are code, arguments, and variables. 

/dps "Captain Obvious"


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-17 Thread Leonel Câmara
I have to say I'm completely stumped. I don't see how this is even 
possible. Are you sure Line 301 is really the line after update_record?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-17 Thread Leonel Câmara
Hey Peter, 

I was trying to help Lisandro, I'm not sure what error you're getting. I've 
seen in other thread that you're getting a ticket error but without looking 
at the ticket and your code I can't guess what's wrong.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-17 Thread Malta Advies
Hello Leonel,

I see you gave information to me about my eventually error code and also
maybe how to solve this.

I have to inform you that I'm not a developer despite. I try to get my site
back on track. For this moment I do not have any help in my neighborhood.

Sure you can see / have the controller code. Just inform me what part of
controller and I send to you in wordpad.

thnx
peter

2018-07-17 14:07 GMT+02:00 Leonel Câmara :

> In virtual methods you should not use row compact notation. You should use
> like row.content.title instead of row.title. So the error can be there.
>
> That said can I see the original code for the controller? Are you doing
> something like row = row.update_record(**data)?
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Best regards,


Peter Hendriks
Manager
*Travel Agency Malta Advies*


*00356 7900 9344*

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-17 Thread Leonel Câmara
In virtual methods you should not use row compact notation. You should use 
like row.content.title instead of row.title. So the error can be there.

That said can I see the original code for the controller? Are you doing 
something like row = row.update_record(**data)?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-17 Thread Lisandro
I don't think the code for update_tsv() is related, because the traceback 
shows that the error is produced even before looking for that method. I 
mean, the error says that the "row" object is None, therefor I think it 
would throw error calling any method. 
But anyway, in case it helps to figure out what is going on, this is the 
code for update_tsv():

def update_tsv(row):
db = current.db
title = detail = ''
if row.title:
 title = row.title.replace("'", "")
if row.detail:
detail = row.detail.replace("'", "")
db.executesql(
 """UPDATE content SET tsv = (SELECT
 setweight(to_tsvector(coalesce(%s, '')), 'A') ||
 setweight(to_tsvector(coalesce(%s, '')), 'B')) WHERE id = %s;""",
 placeholders=[title, detail, row.id])
 return True



El jueves, 12 de julio de 2018, 20:52:38 (UTC-3), Leonel Câmara escribió:
>
> Can I see the code for update_tsv the bug is clearly there?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-12 Thread Leonel Câmara
What virtual method? What does update_tsv do? I can guess it's related to 
some csv representation but that's not a regular row method.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-12 Thread Lisandro
Thank you Leonel for your time.

The code I showed is a bit simplified. 
I do some validation in deed (to requests.vars and request.args). Even 
though, if there is a problem with request.vars (for example, if 
request.vars.age is a string that is not a digit), the update_record would 
throw some error.

Also, if row is None, it would throw an error inmediately when calling 
update_record(), but notice the error is at the line where the virtual 
method is called, right after running .update_record() succesfully. That is 
what I don't understand, how can row be None if the previous line was 
executed succesfully?

First I thought "maybe the content was deleted by another user, or 
something like that", but that does not make sense, since the function is 
executed inside a database transaction, and there is no commit made between 
the two sentences.
It's also weird that it happens very few times (compared to the times that 
it runs succesfully).

Weird... :/
Anyway, I'll keep monitoring the issue and will try to reproduce it.


El jueves, 12 de julio de 2018, 14:05:35 (UTC-3), Leonel Câmara escribió:
>
> You are not validating request.vars.name nor request.vars.age. Is it 
> possible something weird is going on there? Also you're not checking if row 
> is None initially after you get it using request.args(0).  
>   
> Other than that, I don't see how this is even possible. Because a None Row 
> should cause a problem with update_record to begin with.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: row.update_record() leaves row as None (only sometimes)

2018-07-12 Thread Leonel Câmara
You are not validating request.vars.name nor request.vars.age. Is it 
possible something weird is going on there? Also you're not checking if row 
is None initially after you get it using request.args(0).  
  
Other than that, I don't see how this is even possible. Because a None Row 
should cause a problem with update_record to begin with.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.