Re: [web2py] Re: DAL issues ....

2018-12-06 Thread Jim S
It looks like the second line of your view if reassigning something else to 
session.company.  I don't believe the HTML comment tags are not going to 
prevent web2py from executing that statement.

-Jim

On Thursday, December 6, 2018 at 12:22:30 PM UTC-6, Ben Duncan wrote:
>
> Well I was thinking that, BUT:  I'm ALMOST convinced there is a bug in the 
> latest web2py:
>
> CODE 
> --
> Snippet of controllers/default.py
>
> session.company = request.vars['Company']
> Company_ID = "This is a %s of type %s " % (session.company, 
> type(session.company))
> Company_ID = session.company
>
> DbRows = 
> db(db.company.company_number==Company_ID).select(db.company.company_name).first()
> # Co_Name = DbRows['company_name']
>
> session.company_data = DbRows
>
> From view/default/company_login.html:
> {{extend 'layout.html'}}
> 
>
>  onclick="location.href='{{=URL('index')}}'"/>
>
> HOME
>
> Input form
> {{=form}}
> Submitted variables
> {{=BEAUTIFY(request.vars)}}
> {{=(request.vars)}}
>
> Company vars: {{=(request.vars['Company'])}}
> Company session: {{=(session.company)}}
> session data: {{=(session.company_data)}}
>
> Will Display The following:
> (top of form omitted ...)
> . Submitted variables 
> Company : 
> 5
> password : 
> makeit1
> username : 
> be...@linux4ms.net 
> ', 'Company': '5', 
> 'password': 'makeit1', '_formkey': '65ee8396-aac0-4b5c-a255-00be7e7b01ca', 
> '_formname': 'no_table/create'}> Company vars: 5 Company session: 5 session 
> data: 
>
> ___
>
> However, any type of referencing or attempt to do anything with either 
> session.company_date or DbRows 
> always gives a "Nonetype" error of various subtypes (such as __getitem__)
>
> Uncommenting the controller code  of  "# Co_Name = DbRows['company_name']"
> gives the error:
>
> Ticket ID 
>
> 10.13.69.144.2018-12-06.12-17-59.81fd7ae1-6523-47ad-94c7-7b1b480179bd
>  'NoneType' object has no attribute 
> '__getitem__' Version 
> web2py™ Version 2.17.2-stable+timestamp.2018.10.06.18.54.02 
> Python Python 2.7.13: /usr/bin/python (prefix: /opt/rh/python27/root/usr) 
> Traceback 
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
>
> Traceback (most recent call last):
>   File "/data/web2py/web2py/gluon/restricted.py", line 219, in restricted
> exec(ccode, environment)
>   File "/data/web2py/web2py/applications/Mec/controllers/default.py" 
> , line 98, 
> in 
>   File "/data/web2py/web2py/gluon/globals.py", line 421, in 
> self._caller = lambda f: f()
>   File "/data/web2py/web2py/applications/Mec/controllers/default.py" 
> , line 84, 
> in company_login
> Co_Name = DbRows['company_name']
> TypeError: 'NoneType' object has no attribute '__getitem__'
>
>
> As one can see , the Row item exists, it just seems there is no way to get 
> to it ...
>
> Any other ideas ?
>
>
> *Ben Duncan*
> DBA / Chief Software Architect 
> Mississippi State Supreme Court
> Electronic Filing Division
>
>
> On Thu, Dec 6, 2018 at 9:09 AM Leonel Câmara  > wrote:
>
>> What's happening here is that DbRows can become None in this line
>>
>>DbRows = 
>> db(db.company.company_number==Company_ID).select(db.company.company_name).first()
>>
>> So when you do DbRows['company_name'] you can get that error.
>>
>> Basically you need to check if DbRows is None and raise HTTP(404)
>>
>> -- 
>> 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+un...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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: DAL issues ....

2018-12-06 Thread Jim S
Can you try passing DbRows to your view and see if that works?

return dict(form=form, DbRows=DbRows)

Or, throw a print statement in there before session.company_name = 
DbRows['company_name'] to see if DbRows['company_name'] has a value before 
sending to the view?

-Jim



On Thursday, December 6, 2018 at 7:42:27 AM UTC-6, Ben Duncan wrote:
>
> How can something that seems so simple, be so hard? 
>
> I can't seem to get a SINGLE field from the database from DAL:
>
> First is the Error Message (Or on of the many types - but the latest one), 
> then the code
>
> What AM I doing wrong here ?
>
> Als always, thanks ...
>
> Error Message:
> Error ticket for "Mec" Ticket ID 
>
> 10.13.69.144.2018-12-06.07-32-29.8fda8fd6-fe14-47f4-b508-14ce2346465e
>  'NoneType' object has no attribute 
> '__getitem__' Version 
> web2py™ Version 2.17.2-stable+timestamp.2018.10.06.18.54.02 
> Python Python 2.7.13: /usr/bin/python (prefix: /opt/rh/python27/root/usr) 
> Traceback 
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
>
> Traceback (most recent call last):
>   File "/data/web2py/web2py/gluon/restricted.py", line 219, in restricted
> exec(ccode, environment)
>   File "/data/web2py/web2py/applications/Mec/controllers/default.py" 
> , line 96, 
> in 
>   File "/data/web2py/web2py/gluon/globals.py", line 421, in 
> self._caller = lambda f: f()
>   File "/data/web2py/web2py/applications/Mec/controllers/default.py" 
> , line 87, 
> in company_login
> session.company_name = DbRows['company_name']
> TypeError: 'NoneType' object has no attribute '__getitem__'
>
> Error snapshot [image: help] 
> 
>  
>
> ('NoneType' object has no attribute 
> '__getitem__') 
>  Code Here  
> --
>  Ok - Code for controller/default.py
>
> def company_login():
> company.company_name,orderby=db.company.company_name)form = 
> SQLFORM.factory(
> Field('username', label = 'User Name', requires=IS_NOT_EMPTY()),
> Field('password', 'password', label = 
> "Password",requires=IS_NOT_EMPTY()),
> Field('Company', label = 'Court ID',
>  
> requires=IS_IN_DB(db,db.company.company_number,'%(company_name)s')),
> submit_button=' Login ',
> )
>
>   if form.process().accepted:
>response.flash = 'form accepted'
>elif form.errors:
>response.flash = T('form has errors')
>
>session.company = request.vars['Company']
>Company_ID = request.vars['Company']
>DbRows = 
> db(db.company.company_number==Company_ID).select(db.company.company_name).first()
> session.company_name = DbRows['company_name']
>
> return dict(form=form)
>
>
>
>
>
> Thanks again ...
>
>
> *Ben Duncan*
> DBA / Chief Software Architect 
> Mississippi State Supreme Court
> Electronic Filing Division
>

-- 
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: DAL issues ....

2018-12-06 Thread Ben Duncan
Here is something strange as well - working thru the web2py console,
everything works:

[web2py@su-postgres-ben-3 web2py]$ python ./web2py.py -S Mec -M
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2018
Version 2.17.2-stable+timestamp.2018.10.06.18.54.02
Database drivers available: psycopg2, pymysql, imaplib, sqlite3, pg8000,
pyodbc
WARNING:web2py:import IPython error; use default python shell
Python 2.7.13 (default, Feb  8 2017, 06:30:30)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> session.company_id = '5'
>>> Company_ID = session.company_id
>>> print Company_ID
5
>>> DbRows =
db(db.company.company_number==Company_ID).select(db.company.company_name).first()
>>> type(DbRows['company_name'])

>>> DbRows['company_name']
'Number 5 Company'
>>> session.company_data = DbRows
>>> type(DbRows['company_name'])

>>> print session.company_data['company_name']
Number 5 Company
>>>type(DbRows)

>>>





*Ben Duncan*
DBA / Chief Software Architect
Mississippi State Supreme Court
Electronic Filing Division


On Thu, Dec 6, 2018 at 12:22 PM Ben Duncan  wrote:

> Well I was thinking that, BUT:  I'm ALMOST convinced there is a bug in the
> latest web2py:
>
> CODE
> --
> Snippet of controllers/default.py
>
> session.company = request.vars['Company']
> Company_ID = "This is a %s of type %s " % (session.company,
> type(session.company))
> Company_ID = session.company
>
> DbRows =
> db(db.company.company_number==Company_ID).select(db.company.company_name).first()
> # Co_Name = DbRows['company_name']
>
> session.company_data = DbRows
>
> From view/default/company_login.html:
> {{extend 'layout.html'}}
> 
>
>  onclick="location.href='{{=URL('index')}}'"/>
>
> HOME
>
> Input form
> {{=form}}
> Submitted variables
> {{=BEAUTIFY(request.vars)}}
> {{=(request.vars)}}
>
> Company vars: {{=(request.vars['Company'])}}
> Company session: {{=(session.company)}}
> session data: {{=(session.company_data)}}
>
> Will Display The following:
> (top of form omitted ...)
> . Submitted variables
> Company :
> 5
> password :
> makeit1
> username :
> b...@linux4ms.net
>  'makeit1', '_formkey': '65ee8396-aac0-4b5c-a255-00be7e7b01ca', '_formname':
> 'no_table/create'}> Company vars: 5 Company session: 5 session data:  {'company_name': 'Number 5 Company'}>
>
> ___
>
> However, any type of referencing or attempt to do anything with either
> session.company_date or DbRows
> always gives a "Nonetype" error of various subtypes (such as __getitem__)
>
> Uncommenting the controller code  of  "# Co_Name = DbRows['company_name']"
> gives the error:
>
> Ticket ID
>
> 10.13.69.144.2018-12-06.12-17-59.81fd7ae1-6523-47ad-94c7-7b1b480179bd
>  'NoneType' object has no attribute
> '__getitem__' Version
> web2py™ Version 2.17.2-stable+timestamp.2018.10.06.18.54.02
> Python Python 2.7.13: /usr/bin/python (prefix: /opt/rh/python27/root/usr)
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
>
> Traceback (most recent call last):
>   File "/data/web2py/web2py/gluon/restricted.py", line 219, in restricted
> exec(ccode, environment)
>   File "/data/web2py/web2py/applications/Mec/controllers/default.py" 
> , line 98, 
> in 
>   File "/data/web2py/web2py/gluon/globals.py", line 421, in 
> self._caller = lambda f: f()
>   File "/data/web2py/web2py/applications/Mec/controllers/default.py" 
> , line 84, 
> in company_login
> Co_Name = DbRows['company_name']
> TypeError: 'NoneType' object has no attribute '__getitem__'
>
>
> As one can see , the Row item exists, it just seems there is no way to get
> to it ...
>
> Any other ideas ?
>
>
> *Ben Duncan*
> DBA / Chief Software Architect
> Mississippi State Supreme Court
> Electronic Filing Division
>
>
> On Thu, Dec 6, 2018 at 9:09 AM Leonel Câmara 
> wrote:
>
>> What's happening here is that DbRows can become None in this line
>>
>>DbRows =
>> db(db.company.company_number==Company_ID).select(db.company.company_name).first()
>>
>> So when you do DbRows['company_name'] you can get that error.
>>
>> Basically you need to check if DbRows is None and raise HTTP(404)
>>
>> --
>> 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 

Re: [web2py] Re: DAL issues ....

2018-12-06 Thread Ben Duncan
Well I was thinking that, BUT:  I'm ALMOST convinced there is a bug in the
latest web2py:

CODE
--
Snippet of controllers/default.py

session.company = request.vars['Company']
Company_ID = "This is a %s of type %s " % (session.company,
type(session.company))
Company_ID = session.company

DbRows =
db(db.company.company_number==Company_ID).select(db.company.company_name).first()
# Co_Name = DbRows['company_name']

session.company_data = DbRows

>From view/default/company_login.html:
{{extend 'layout.html'}}




HOME

Input form
{{=form}}
Submitted variables
{{=BEAUTIFY(request.vars)}}
{{=(request.vars)}}

Company vars: {{=(request.vars['Company'])}}
Company session: {{=(session.company)}}
session data: {{=(session.company_data)}}

Will Display The following:
(top of form omitted ...)
. Submitted variables
Company :
5
password :
makeit1
username :
b...@linux4ms.net
 Company vars: 5 Company session: 5 session data: 
___

However, any type of referencing or attempt to do anything with either
session.company_date or DbRows
always gives a "Nonetype" error of various subtypes (such as __getitem__)

Uncommenting the controller code  of  "# Co_Name = DbRows['company_name']"
gives the error:

Ticket ID

10.13.69.144.2018-12-06.12-17-59.81fd7ae1-6523-47ad-94c7-7b1b480179bd
 'NoneType' object has no attribute
'__getitem__' Version
web2py™ Version 2.17.2-stable+timestamp.2018.10.06.18.54.02
Python Python 2.7.13: /usr/bin/python (prefix: /opt/rh/python27/root/usr)
Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

Traceback (most recent call last):
  File "/data/web2py/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
  File "/data/web2py/web2py/applications/Mec/controllers/default.py"
,
line 98, in 
  File "/data/web2py/web2py/gluon/globals.py", line 421, in 
self._caller = lambda f: f()
  File "/data/web2py/web2py/applications/Mec/controllers/default.py"
,
line 84, in company_login
Co_Name = DbRows['company_name']
TypeError: 'NoneType' object has no attribute '__getitem__'


As one can see , the Row item exists, it just seems there is no way to get
to it ...

Any other ideas ?


*Ben Duncan*
DBA / Chief Software Architect
Mississippi State Supreme Court
Electronic Filing Division


On Thu, Dec 6, 2018 at 9:09 AM Leonel Câmara  wrote:

> What's happening here is that DbRows can become None in this line
>
>DbRows =
> db(db.company.company_number==Company_ID).select(db.company.company_name).first()
>
> So when you do DbRows['company_name'] you can get that error.
>
> Basically you need to check if DbRows is None and raise HTTP(404)
>
> --
> 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.
>

-- 
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: DAL issues ....

2018-12-06 Thread Leonel Câmara
What's happening here is that DbRows can become None in this line

   DbRows = 
db(db.company.company_number==Company_ID).select(db.company.company_name).first()

So when you do DbRows['company_name'] you can get that error.

Basically you need to check if DbRows is None and raise HTTP(404)

-- 
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: DAL issues on production server (xen VM)

2013-12-17 Thread Niphlod
they should be separated and they are separated from what I see in the 
code. the db connection of the scheduler is on the main thread while 
the one used by the task is inside the spawned process (the executor() 
function). I don't see connections shared between the two.

On Monday, December 16, 2013 10:29:41 PM UTC+1, Yassen D. wrote:

 Issue resolved. The source of all trouble was that the Scheduler uses the 
 same db connection as the task it executes. Thus output updates (print 
 '!clear!%(progress)s' % progress) changes the connection status, randomly, 
 hence the strange exceptions.

 Suggestion: explicitly mention this as a gotcha in the scheduler section 
 of the w2p book.

 Cheers,
 Yassen


-- 
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/groups/opt_out.


[web2py] Re: DAL issues on production server (xen VM)

2013-12-16 Thread Yassen D.
Issue resolved. The source of all trouble was that the Scheduler uses the 
same db connection as the task it executes. Thus output updates (print 
'!clear!%(progress)s' % progress) changes the connection status, randomly, 
hence the strange exceptions.

Suggestion: explicitly mention this as a gotcha in the scheduler section of 
the w2p book.

Cheers,
Yassen

-- 
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/groups/opt_out.


[web2py] Re: DAL issues on production server (xen VM)

2013-12-15 Thread Massimo Di Pierro
Do you user virtual fields? Are you doing migrations while the scheduler 
tasks are running. This is strange because it is a very fundamental piece 
of web2py code that has not changed in long time:

for (i,row) in enumerate(rows):
for (j,colname) in enumerate(colnames):
value = row[j]
 

On Sunday, 15 December 2013 15:39:34 UTC-6, Yassen D. wrote:

 Hello guys,

 Recently updated from w2p 2.2.1 to 2.8.2 as I was advised; now random 
 errors on database inserts started to raise for stuff that worked on the 
 old version (2.2.1). Tracebacks of the two errors:

 This is the most common one:

   File /home/www-data/web2py/gluon/scheduler.py, line 238, in executor
 result = dumps(_function(*args, **vars))
   File applications/socialjack/modules/contactManager.py, line 97, in 
 importSocialMediaContacts
 if db.contacts.insert(contact_name=contact_name, url=url, 
 network=network, user_id=user_id, ring=4):
   File /home/www-data/web2py/gluon/dal.py, line 9118, in insert
 ret =  self._db._adapter.insert(self, self._listify(fields))
   File /home/www-data/web2py/gluon/dal.py, line 1347, in insert
 id = self.lastrowid(table)
   File /home/www-data/web2py/gluon/dal.py, line 2724, in lastrowid
 return int(self.cursor.fetchone()[0])
 TypeError: 'NoneType' object has no attribute '__getitem__'

 And I just noticed one more (more rare):

   File /home/www-data/web2py/gluon/scheduler.py, line 238, in executor
 result = dumps(_function(*args, **vars))
   File applications/socialjack/modules/contactManager.py, line 97, in 
 importSocialMediaContacts
 if not db((db.contacts.url == url)  (db.contacts.user_id == 
 user_id)).select():
   File /home/www-data/web2py/gluon/dal.py, line 10471, in select
 return adapter.select(self.query,fields,attributes)
   File /home/www-data/web2py/gluon/dal.py, line 1862, in select
 return self._select_aux(sql,fields,attributes)
   File /home/www-data/web2py/gluon/dal.py, line 1843, in _select_aux
 return processor(rows,fields,self._colnames,cacheable=cacheable)
   File /home/www-data/web2py/gluon/dal.py, line 2227, in parse
 value = row[j]
 IndexError: tuple index out of range

 These appear during long-running scheduler task that inserts records into 
 a db table. The exact insert code is:

 if not db((db.contacts.url == url)  (db.contacts.user_id == 
 user_id)).select():
 if db.contacts.insert(contact_name=contact_name, url=url, 
 network=network, user_id=user_id, ring=4):
 import_count += 1

 Any suggestions why this happens?

 The app runs on an ubuntu 12.04 xen VM;
 w2p version: 2.8.2-stable+timestamp.2013.12.14.20.02.42
 mysql-server version: 5.5.29-0ubuntu0.12.04.2

 Any help is very much appreciated, thanks!
 Yassen






-- 
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/groups/opt_out.


[web2py] Re: DAL issues on production server (xen VM)

2013-12-15 Thread Yassen D.


On Monday, December 16, 2013 2:46:00 AM UTC+2, Massimo Di Pierro wrote:

 Do you user virtual fields? Are you doing migrations while the scheduler 
 tasks are running. This is strange because it is a very fundamental piece 
 of web2py code that has not changed in long time:



Massimo, thanks for your reply!

No migration is done at all. No virtual fields as well. What I forgot to 
tell is that when it used to work, it was NOT run as a scheduled task, it 
was run within a controller.

I also find this very very strange -- the return 
int(self.cursor.fetchone()[0]) should always work once the record has been 
inserted. Also, It  breaks at a random record -- it is different each time. 
Seems like the MySQL server gets confused somehow ...

Can it be a memory problem? Or the VM system is not syncing properly? Just 
shooting in the dark.
Any clue anyone?  Thanks!
Yassen

-- 
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/groups/opt_out.