Friday, November 23, 2012

Invalid properties don't throw errors?

I'm stumped.

I have a Django project that's fairly far along--I'm able to use it internally.

A few days ago while trying to debug a function, I noticed I was settings a property incorrectly.

Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> u = User.objects.get(pk=1)
>>> u.user = 'test'
>>> 

No error.  It should be 'u.username'.

So I tried a few more.

Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> u = User.objects.get(pk=1)
>>> u.sdbgnois74gn = 'test'
>>> 

No error is thrown for trying to set an invalid property.

I tried blowing away my virtualenv and reinstalling.  Same issue.

Passing invalid parameters while creating a new object throws errors, but not after the object is created.

>>> django.VERSION
(1, 4, 2, 'final', 0)
>>> c = Company(doesnotexist='123')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/aaron/.virtualenvs/tapp/local/lib/python2.7/site-packages/django/db/models/base.py", line 367, in __init__
    raise TypeError("'%s' is an invalid keyword argument for this function" % kwargs.keys()[0])
TypeError: 'doesnotexist' is an invalid keyword argument for this function
>>> c = Company(name='123')
>>> c.doesnotexist = '123'
>>>

I have never witnessed this behavior before in python.  Any pointers on where I should start digging?

-A

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/36qxKSnxvWcJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate