I've found why there was a difference between these similar situations. First of the os.path.exists test I need to add a test for checking if the field is empty or not: if user.image_user32x32:
---------------------- Gael Princivalle 2017-02-19 7:58 GMT+01:00 Gael Princivalle <gaelprinciva...@gmail.com>: > Thank you Leonel but u.image_user16x16 contains always the file name, so > the test will return always True. > The problem is that the image file is not created on the disk so I have to > test if it exist. > > At this point it's not so easy to do. > The application call for these computed images from the auth.user session > and tables that have the auth.signature. > > This works: > os.path.exists(os.path.join(request.folder,'uploads',auth.user. > image_user16x16)) > > This works: > event = db.events(event_id) > os.path.exists(os.path.join(request.folder,'uploads',event.created_by. > image_user32x32)) > > This works: > event_comments = db(db.events_comments.commented_event == event_id).select > (orderby=db.events_comments.created_on) > os.path.exists(os.path.join(request.folder,'uploads',event_comment. > created_by.image_user32x32)) > > This don't works: > user_followers = db((db.followers.to_user == to_user_id) & > (db.followers.status > == True)).select() > os.path.exists(os.path.join(request.folder,'uploads',user_follower. > created_by.image_user32x32)) > > Traceback is: > File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/restricted.py", line > 227, in restricted > exec ccode in environment > File "/home/tasko/webapps/w2p_2_14_16/web2py/applications/ > mtbconnection/controllers/f_ajax.py", line 1081, in <module> > File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/globals.py", line 417 > , in <lambda> > self._caller = lambda f: f() > File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/tools.py", line 4241, > in f > return action(*a, **b) > File "/home/tasko/webapps/w2p_2_14_16/web2py/applications/ > mtbconnection/controllers/f_ajax.py", line 143, in get_followers > if os.path.exists(os.path.join(request.folder,'uploads',user_follower. > created_by.image_user32x32)): > File "/usr/lib64/python2.7/posixpath.py", line 75, in join > if b.startswith('/'): > AttributeError: 'NoneType' object has no attribute 'startswith' > > And also this don't works, same error: > events = db((period_query) & > (db.events.geometry.st_within(geoPolygon((west, south), ( > east, south), (east, north), (west, north), (west, south))))).select( > limitby=(0, 50), > orderby=db.events.event_datetime) > os.path.exists(os.path.join(request.folder,'uploads',event.created_by. > image_user32x32)) > > Traceback is: > File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/restricted.py", line > 227, in restricted > exec ccode in environment > File "/home/tasko/webapps/w2p_2_14_16/web2py/applications/ > mtbconnection/controllers/f_ajax.py", line 1081, in <module> > File "/home/tasko/webapps/w2p_2_14_16/web2py/gluon/globals.py", line 417, > in <lambda> > self._caller = lambda f: f() > File "/home/tasko/webapps/w2p_2_14_16/web2py/applications/ > mtbconnection/controllers/f_ajax.py", line 352, in get_main_events > html = get_events_html(events) > File "/home/tasko/webapps/w2p_2_14_16/web2py/applications/ > mtbconnection/controllers/f_ajax.py", line 169, in get_events_html > if os.path.exists(os.path.join(request.folder,'uploads',event.created_by > .image_user32x32)): > File "/usr/lib64/python2.7/posixpath.py", line 75, in join > if b.startswith('/'): > AttributeError: 'NoneType' object has no attribute 'startswith' > > > The two situations where it don't works are similar to events_comments > situation that works. What could be the difference? > If I replace "if os.path..." with the simple test if > "event.created_by.image_user32x32" I don't have this 'NoneType' error. > > I 've found on the web this about the NoneType error: > >> NoneType means that instead of an instance of whatever Class or Object >> you think you're working with, you've actually got None. That usually means >> that an assignment or function call up above failed or returned an >> unexpected result. > > > Ok, but I cannot understand where is this attribute that don't exist. > Someone can give me a hand? > > Il giorno sabato 18 febbraio 2017 18:14:30 UTC+1, Leonel Câmara ha scritto: >> >> Gael that's one of the bugs i've referred fo computed fields they are not >> updated in session. >> >> Notice that you use >> >> *auth.user*.image_user16x16 >> >> Well auth.user is nothing other than *session*.auth.user >> >> You are also using os.path.exists wrong as you're giving it an URL. >> >> For instance I'm sure this will work after register: >> >> >> # put this function in a model >> def get_img(user): >> u = db.auth_user[user.id] >> if u and u.image_user16x16: >> return URL('default', 'download', args=u.image_user16x16) >> else: >> return URL('static/images', 'favicon.png') >> >> # then in a view >> <img src="{{=get_img(auth.user)}}"> >> >> Note that this solution is very inefficient because you are reloading the >> user from the database, just for this image, every single time. My point is >> that this will prove to you that this is a session not being updated >> problem. >> >> >> -- > 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 a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/web2py/1idjBK4puQQ/unsubscribe. > To unsubscribe from this group and all its topics, 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.