Skip to content

Commit

Permalink
Fix DictionaryField to conform to the IDataManager spec: get() should…
Browse files Browse the repository at this point in the history
… raise an exception if no value can be found.
  • Loading branch information
wichert committed May 10, 2010
1 parent 8ed162b commit f6391c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ CHANGES
- Bugfix: applyChanges should not try to compare old and new values of the old
value can not be accessed.

- Fix DictionaryField to conform to the IDataManager spec: get() should raise
an exception if no value can be found.


2.3.3 (2010-04-20)
------------------

Expand Down
6 changes: 5 additions & 1 deletion src/z3c/form/datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from z3c.form import interfaces

_marker = []

class DataManager(object):
"""Data manager base class."""
Expand Down Expand Up @@ -117,7 +118,10 @@ def __init__(self, data, field):

def get(self):
"""See z3c.form.interfaces.IDataManager"""
return self.data.get(self.field.__name__, self.field.missing_value)
value = self.data.get(self.field.__name__, _marker)
if value is _marker:
raise AttributeError
return value

def query(self, default=interfaces.NO_VALUE):
"""See z3c.form.interfaces.IDataManager"""
Expand Down
3 changes: 3 additions & 0 deletions src/z3c/form/datamanager.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ The datamanager can really only deal with dictionaries and mapping types:
Let's now access the name:

>>> nameDm.get()
Traceback (most recent call last):
...
AttributeError

>>> nameDm.query()
<NO_VALUE>
Expand Down

0 comments on commit f6391c0

Please sign in to comment.