cos-archives / modular-odm

A database-agnostic Object-Document Mapper for Python.
Apache License 2.0
13 stars 18 forks source link

Disallow mutable defaults for fields #121

Open lyndsysimon opened 9 years ago

lyndsysimon commented 9 years ago

Current Behavior

If the value set for a field default is callable, it is called when the default is used. Else, the default value is effectively set to lambda: copy.deepcopy(<default>).

Calling copy.deepcopy on some values may have unexpected results, including a frame overflow if the object is recursively nested.

Desired Behavior

If the value set for a field default is callable, it is called when the default is used. If the value is mutable, TypeError should be raised with a useful message. Else, the default object should be used directly.