Why cant fetch rows using select when importing models using the -M option?

25 views
Skip to first unread message

Bernardo Leon

unread,
Oct 3, 2016, 12:40:09 PM10/3/16
to web2py-users
I load my application in this way:
$ python web2py.py -M -S myexistingapp


if I run:

db(db.my_table.logged_user == auth.user_id).select()

I get: <Rows (0)>

even if I run:

db(db.my_table.logged_user == 1).select()

or 

db(db.my_table.logged_user == 1L).select()

I get: <Rows (0)>

but if I run:

db.executesql('select * from my_table where logged_user = 1;')

I get my list of rows.

Why is this happening? I found this issue because I was getting <Rows (0)> on my scheduler.py task.

Thanks in advance for any help I get with this issue.

Anthony

unread,
Oct 3, 2016, 1:01:22 PM10/3/16
to web2py-users
Note, auth.user_id will be None in the shell.

What happens if you do (note the ._select rather than .select):

db.executesql(db(db.my_table.logged_user == 1)._select())

Anthony

Bernardo Leon

unread,
Oct 3, 2016, 1:20:21 PM10/3/16
to web2py-users
Thanks for noting it, now I am passing the user id as part of pvars of the task but with not much progress, though

If I run that query I get an empty list: []

Bernardo Leon

unread,
Oct 4, 2016, 10:36:57 AM10/4/16
to web2py-users
Now if I only run

db(db.my_table.logged_user == 1)._select()

I get:

'SELECT  my_table.id, my_table.my_column, my_table.logged_user FROM my_table WHERE ((my_table.logged_user = 1) AND (my_table.logged_user IS NULL));'

Why is the query is trying to validate that the logged_user is null? thanks!

Anthony

unread,
Oct 4, 2016, 12:19:50 PM10/4/16
to web2py-users
On Tuesday, October 4, 2016 at 10:36:57 AM UTC-4, Bernardo Leon wrote:
Now if I only run

db(db.my_table.logged_user == 1)._select()

I get:

'SELECT  my_table.id, my_table.my_column, my_table.logged_user FROM my_table WHERE ((my_table.logged_user = 1) AND (my_table.logged_user IS NULL));'

Why is the query is trying to validate that the logged_user is null? thanks!

Seems odd. Do you have a common filter defined somewhere? What do you get with:

db(db.my_table.logged_user == 1, ignore_common_filters=True)._select()

What does the table definition look like? Is there some code you're not showing (presumably the real table name is not "my_table")?

You may need to attach an app that reproduces the problem.

Anthony

Bernardo Leon

unread,
Oct 4, 2016, 12:42:26 PM10/4/16
to web2py-users
Yeah, you nailed it, I didn't even knew that the ignore_common_filters parameter even existed (I guess I forgot about my common_filter in the logged_user field). Now my query is returning everything ok.

Thank you! and my table's name is not 'my_table' I only use those names to simplify my questions ;)
Reply all
Reply to author
Forward
0 new messages