Ticket #458 (closed enhancement: fixed)

Opened 14 months ago

Last modified 13 months ago

generate exception when encoding duplicate keys

Reported by: arman0 Owned by: nick
Priority: blocker Milestone: 0.4.1
Component: Encoder Version: 0.4
Keywords: Cc:
Fixed in revision: Branch:
Author:

Description (last modified by thijs) (diff)

>>> pyamf.decode(pyamf.encode({0:0, '0':1})).next()
{u'0': 1}

My guess is that the user almost always has a bug when encoding a python dict which will result in duplicate AS object keys. Therefore, it would be help for pyamf to raise an exception in such cases.

-arman

Change History

Changed 14 months ago by thijs

  • description modified (diff)

Changed 13 months ago by nick

  • status changed from new to accepted

Changed 13 months ago by nick

Changed 13 months ago by nick

  • keywords review added
  • owner changed from nick to arman0
  • status changed from accepted to assigned

Encoding the example dict now raises an AttributeError:

>>> import pyamf
pyamf.encode({0:0, '0':1})
>>> pyamf.encode({0:0, '0':1})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pyamf/__init__.py", line 1069, in encode
    encoder.writeElement(el)
  File "pyamf/amf0.py", line 541, in writeElement
    func(data)
  File "pyamf/amf0.py", line 758, in writeObject
    obj_attrs = self._getObjectAttrs(o, alias)
  File "pyamf/amf0.py", line 722, in _getObjectAttrs
    obj_attrs = util.get_attrs(o)
  File "pyamf/util/__init__.py", line 732, in get_attrs
    'different key types?' % (sk,))
AttributeError: A duplicate attribute (0) was already found in this collection, are you mixing different key types?

Changed 13 months ago by thijs

  • keywords review removed
  • owner changed from arman0 to nick

I added a docstring for the AttributeError in r2204.

The test from the ticket description worked and ParseDump succeeded, so ready to merge.

Changed 13 months ago by nick

  • status changed from assigned to closed
  • resolution set to fixed

Merged in r2206.

Note: See TracTickets for help on using tickets.