librelist archives

« back to archive

flash message error

flash message error

From:
linnchord
Date:
2011-11-24 @ 01:44
hi guys, 

When I make message flash, somehow genarate a error
AttributeError: 'tuple' object has no attribute 'append'

the source code of flask look like it is a list
session.setdefault('_flashes', []).append((category, message))

When this turn to be a tuple? Why?
Why this happened? And how to make it good?
Thanks.


-------------------------------
linnchord@gmail.com

Re: [flask] flash message error

From:
Armin Ronacher
Date:
2011-11-24 @ 06:30
Hi,

On 11/24/11 2:44 AM, linnchord wrote:
> When I make message flash, somehow genarate a error
> 
> AttributeError: 'tuple' object has no attribute 'append'
Sounds like something in the session backend sets _flashes to a tuple
isntead of a list.  This can happen if you set this yourself or if you
have a session backend that cannot deal with lists and is returning
tuples instead.  I do not know if such a session system currently
exists, but I would not be surprised seeing how msgbuf or whatever it is
I was testing last time was randomly converting types around.

To debug this issue:

1. Do you use a custom session backend?
2. Do you set _flashes to an empty tuple anywhere?


Regards,
Armin

回复: flash message error

From:
linnchord
Date:
2011-11-24 @ 16:11
Got it!

I use msgpack to serialize the session dict, that will turn the list to 
tuple when load from redis. Sucks!  

-------------------------------
linnchord@gmail.com


在 2011年11月24日星期四,下午2:30,Armin Ronacher 写道:

> Hi,
>  
> On 11/24/11 2:44 AM, linnchord wrote:
> > When I make message flash, somehow genarate a error
> >  
> > AttributeError: 'tuple' object has no attribute 'append'
> Sounds like something in the session backend sets _flashes to a tuple
> isntead of a list. This can happen if you set this yourself or if you
> have a session backend that cannot deal with lists and is returning
> tuples instead. I do not know if such a session system currently
> exists, but I would not be surprised seeing how msgbuf or whatever it is
> I was testing last time was randomly converting types around.
>  
> To debug this issue:
>  
> 1. Do you use a custom session backend?
> 2. Do you set _flashes to an empty tuple anywhere?
>  
>  
> Regards,
> Armin
>  
>  

Re: [flask] flash message error

From:
Lix Xu
Date:
2011-11-24 @ 02:03
Why not use flash(message, category)?

On Thu, Nov 24, 2011 at 09:44, linnchord <linnchord@gmail.com> wrote:

>  hi guys,
>
> When I make message flash, somehow genarate a error
>
>
> AttributeError: 'tuple' object has no attribute 'append'
>
>
> the source code of flask look like it is a list
>
>
> session.
>  setdefault('_flashes', []).append((category, message))
>
>
> When this turn to be a tuple? Why?
>
> Why this happened? And how to make it good?
>
> Thanks.
>
>
> -------------------------------
> linnchord@gmail.com
>
>

回复: flash message error

From:
linnchord
Date:
2011-11-24 @ 02:09
is that matter? my call code is
flash(u'add successful!','ok')



-------------------------------
linnchord@gmail.com


在 2011年11月24日星期四,上午10:03,Lix Xu 写道:

> Why not use flash(message, category)?
>  
> On Thu, Nov 24, 2011 at 09:44, linnchord <linnchord@gmail.com 
(mailto:linnchord@gmail.com)> wrote:
> > hi guys,  
> >  
> > When I make message flash, somehow genarate a error
> > AttributeError: 'tuple' object has no attribute 'append'
> >  
> > the source code of flask look like it is a list
> > session. setdefault('_flashes', []).append((category, message))
> >  
> > When this turn to be a tuple? Why?
> > Why this happened? And how to make it good?
> > Thanks.
> >  
> >  
> > -------------------------------
> > linnchord@gmail.com (mailto:linnchord@gmail.com)
> >  
>