[web2py] problems after changeset # ce20196cd7b895029ed667ecff505987ee83d727 - (ce20196cd7b8) storage patch

2011-11-02 Thread Carlos
Hi,

I'm using web2py latest trunk on win7.

As soon as I applied the following changeset:

ce20196cd7b895029ed667ecff505987ee83d727 - (ce20196cd7b8) storage patch

I got errors both in shell and web requests ...

auth.settings.hmac_key = 'sha512:5fd2a4d2-d703-476c-8184-800b84e453b8'
 File C:\web2py\gluon\storage.py, line 199, in __setattr__
raise SyntaxError, 'setting key \'%s\' does not exist' % key
SyntaxError: setting key 'hmac_key' does not exist

If I reload the immediate prior changeset, everything works ok again.

Based on what I see in this change, you are now removing the Storage key 
also via __setitem__ (in addition to __setattr__).

But I need a way to assign None to a Storage key, for which I was using: 
mystorage['key'] = None (which did assign None and did not remove the key).

Now I would have no way to assign a None value to a Storage key?.

Plus the above error I get in Settings.

Can this change be reverted?, or what do you recommend instead?.

Thanks,

   Carlos



Re: [web2py] problems after changeset # ce20196cd7b895029ed667ecff505987ee83d727 - (ce20196cd7b8) storage patch

2011-11-02 Thread Jonathan Lundell
On Nov 2, 2011, at 7:59 AM, Carlos wrote:

 I'm using web2py latest trunk on win7.
 
 As soon as I applied the following changeset:
 
 ce20196cd7b895029ed667ecff505987ee83d727 - (ce20196cd7b8) storage patch
 
 I got errors both in shell and web requests ...
 
 auth.settings.hmac_key = 'sha512:5fd2a4d2-d703-476c-8184-800b84e453b8'
  File C:\web2py\gluon\storage.py, line 199, in __setattr__
 raise SyntaxError, 'setting key \'%s\' does not exist' % key
 SyntaxError: setting key 'hmac_key' does not exist
 
 If I reload the immediate prior changeset, everything works ok again.
 
 Based on what I see in this change, you are now removing the Storage key also 
 via __setitem__ (in addition to __setattr__).
 
 But I need a way to assign None to a Storage key, for which I was using: 
 mystorage['key'] = None (which did assign None and did not remove the key).
 
 Now I would have no way to assign a None value to a Storage key?.
 
 Plus the above error I get in Settings.
 
 Can this change be reverted?, or what do you recommend instead?.
 

I'll take a look. The patch was intended to make Storage behave consistently 
with respect to access through attributes and through keys, mainly so that 
s.key and s['key'] would behave the same way--that is, both yield None when the 
key isn't present in the underlying dict.

The behavior on storing None is along those lines: s.key = None deletes the 
key+value from the dict, and the patch makes s['key'] = None do the same 
thing. I'm frankly not sure that deletion is a great idea in any case; deletion 
should IMO be explicit.

Finally, the settings error appears to be a bug.

I'll send Massimo a patch ASAP to revert the new deletion and fix the error; I 
need to add a case to the unit test.

Re: [web2py] problems after changeset # ce20196cd7b895029ed667ecff505987ee83d727 - (ce20196cd7b8) storage patch

2011-11-02 Thread Carlos
Hi,

I'm using Storage objects throughout my code, and compare vs None values to 
perform certain specific actions.

Thanks!,

   Carlos



Re: [web2py] problems after changeset # ce20196cd7b895029ed667ecff505987ee83d727 - (ce20196cd7b8) storage patch

2011-11-02 Thread Anthony
On Wednesday, November 2, 2011 11:46:49 AM UTC-4, Carlos wrote:

 Hi,

 I'm using Storage objects throughout my code, and compare vs None values 
 to perform certain specific actions.


In your code, can you use the attribute access method, which will return 
None when the attribute doesn't exist:

myobj.mykey is None

will be true if mykey doesn't exist. Or do you need to use the 
myobj['mykey'] method because the key is stored in a variable or something 
like that? In the latter case, I suppose there are other possibilities, 
such as

mykey in myobj

 


 Thanks!,

Carlos



Re: [web2py] problems after changeset # ce20196cd7b895029ed667ecff505987ee83d727 - (ce20196cd7b8) storage patch

2011-11-02 Thread Carlos
Hi Anthony,

One example is to pass an Storage object to form.accepts, containing None 
values.

   Carlos



Re: [web2py] problems after changeset # ce20196cd7b895029ed667ecff505987ee83d727 - (ce20196cd7b8) storage patch

2011-11-02 Thread Jonathan Lundell
On Nov 2, 2011, at 9:09 AM, Carlos wrote:

 One example is to pass an Storage object to form.accepts, containing None 
 values.
 

It's a closed issue anyway, since Settings (and who knows what else) depends on 
it.

I'm sure it's too late now, for compatibility reasons, but I think that deletes 
should be explicit in all cases.

Re: [web2py] problems after changeset # ce20196cd7b895029ed667ecff505987ee83d727 - (ce20196cd7b8) storage patch

2011-11-02 Thread Anthony
On Wednesday, November 2, 2011 12:09:12 PM UTC-4, Carlos wrote:

 Hi Anthony,

 One example is to pass an Storage object to form.accepts, containing None 
 values.


I see -- so the keys have to actually exist. 


Re: [web2py] problems after changeset # ce20196cd7b895029ed667ecff505987ee83d727 - (ce20196cd7b8) storage patch

2011-11-02 Thread Carlos
Hi Jonathan,

I completely agree about deletes to be explicit in all cases.

In fact, Storage.__setattr__ should be changed to not auto-delete on None 
value, but I guess it's not possible for compatibility reasons?.

Thanks again,

   Carlos



Re: [web2py] problems after changeset # ce20196cd7b895029ed667ecff505987ee83d727 - (ce20196cd7b8) storage patch

2011-11-02 Thread Jonathan Lundell
On Nov 2, 2011, at 10:06 AM, Carlos wrote:

 I completely agree about deletes to be explicit in all cases.
 
 In fact, Storage.__setattr__ should be changed to not auto-delete on None 
 value, but I guess it's not possible for compatibility reasons?.
 

That's my assumption, yes.