On Thursday, May 2, 2019 at 2:42:15 AM UTC-7, [email protected] wrote:
>
> Can't do that. As I told you the query has to be executed on the 
> destination.
>
> Huh?  I'm confused.   You're trying to pass a query (not the results of 
the select), and having trouble pickling request.args[0].  I'm guessing 
that the type of object that request.args is why there's a pickling error.  
So copy the string you're interested in to a simple[r] local string 
variable, form the query with that, and pickle that.

If the request.args[0] that you want to use in the query isn't known when 
you set the session variable because it is the request.args[0] of the later 
request, then yeah, you can't pass it in the session variable.  In that 
case, I wouldn't try to pass the query; I'd pass the table name and the 
field, and maybe the error message.  Those are all simple string arguments.

Another approach, since these look a lot like validators to me, is to 
forget about using session, and simply define the functions in your model, 
which puts the function into your name space.

I have to admit that when I read your questions, I am sometimes wpndering 
if you are trying to do things in a much more complicated way than 
necessary.  It is true that I don't know your use cases or workflow, or the 
particulars of your "problem space", and that the applications I do tend to 
be simple, so my ignorance is probably why I get that impression, but your 
questions seem to stand out in this forum.  However, you also have 
demonstrated both a perseverance and a problem solving ability, so I admire 
what you've done.

/dps


 

> quinta-feira, 2 de Maio de 2019 às 01:01:01 UTC+1, Dave S escreveu:
>>
>>
>>
>> On Wednesday, May 1, 2019 at 2:47:53 PM UTC-7, [email protected] wrote:
>>>
>>> Yes, I read it..
>>>
>>> If you try to save it on a session var (to pass between requests) it 
>>> will return a pickling error (or not), depending on the query.
>>> I tried to save this 
>>> db.equipment.sn_counter_id == request.args[0]
>>> and it returns a pickling error.
>>> Probably because of request.args[0].
>>>
>>>
>> Does copying request.args[0] to a local [string] variable help?
>>
>> /dps
>>  
>>
>>>
>>> quarta-feira, 1 de Maio de 2019 às 22:43:06 UTC+1, Dave S escreveu:
>>>>
>>>> <
>>>>
>>>> On Wednesday, May 1, 2019 at 2:22:11 PM UTC-7, [email protected] wrote:
>>>>>
>>>>> What do you mean?
>>>>>
>>>>> I don't want to serialize the query.
>>>>> And I want the query to only be executed on the desalination 
>>>>> controller.
>>>>>
>>>>>
>>>> Did you read the reference?
>>>>
>>>> <quote>
>>>>
>>>> You can even build a query (using operators like ==, !=, <, >, <=, >=, 
>>>> like, belongs) and store the query in a variable q such as in:
>>>>
>>>> >>> q = name == 'Alex'
>>>>
>>>> </quote>
>>>>  
>>>>
>>>>  
>>>>
>>>>>
>>>>> quarta-feira, 1 de Maio de 2019 às 22:00:27 UTC+1, Dave S escreveu:
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wednesday, May 1, 2019 at 1:53:25 PM UTC-7, [email protected] 
>>>>>> wrote:
>>>>>>>
>>>>>>> Got the answer in the Telegram chat. Using eval.
>>>>>>> It's a dangerous solution but works.
>>>>>>>
>>>>>>>
>>>>>> What about storing a querey, as in
>>>>>> <URL:
>>>>>> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Query-Set-Rows
>>>>>> >
>>>>>> ?
>>>>>>
>>>>>> /dps
>>>>>>  
>>>>>>
>>>>>>>
>>>>>>> quarta-feira, 1 de Maio de 2019 às 10:07:45 UTC+1, [email protected] 
>>>>>>> escreveu:
>>>>>>>>
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> How to pass a query set string or a string with a select/count to 
>>>>>>>> be executed in another controller?
>>>>>>>>
>>>>>>>> On one controller I create one of these 4 examples:
>>>>>>>> session.checks = [
>>>>>>>>         'db(db.equipment.sn_counter_id == request.args[0]).count()'
>>>>>>>> ,
>>>>>>>>         T('Cannot be deleted while assigned to an equipment.'),
>>>>>>>> ]
>>>>>>>>
>>>>>>>> session.checks = [
>>>>>>>>         QUERY_FOR_COUNT,
>>>>>>>>         'db.equipment.sn_counter_id == request.args[0]',
>>>>>>>>         T('Cannot be deleted while assigned to an equipment.'),
>>>>>>>> ]
>>>>>>>>
>>>>>>>> session.checks = [
>>>>>>>>         'db(db.equipment.depends_on == request.args[0]).select()',
>>>>>>>>         T('Cannot be deleted while dependent on an option.'),
>>>>>>>> ]
>>>>>>>>
>>>>>>>> session.checks = [
>>>>>>>>         QUERY_FOR_SELECT,
>>>>>>>>         'db.equipment.depends_on == request.args[0]',
>>>>>>>>         T('Cannot be deleted while dependent on an option.'),
>>>>>>>> ]
>>>>>>>>
>>>>>>>> and then execute it on another controller using something similar 
>>>>>>>> to (of course my example below doesn't work):
>>>>>>>>             if session.checks[0]:
>>>>>>>>                 session.flash = session.checks[1]
>>>>>>>>                 redirect(return_to)
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> JM
>>>>>>>>
>>>>>>>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to