Skip to content

Commit

Permalink
Fix FieldDescriptor default value bug. Close #49.
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed May 14, 2015
1 parent 90d2c40 commit fc9eb80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/test_replies.py
Expand Up @@ -102,3 +102,13 @@ def test_music_reply_properties(self):
self.assertEqual('test', reply.description)
self.assertEqual('http://www.qq.com', reply.music_url)
self.assertTrue(reply.hq_music_url is None)

def test_multi_article_reply(self):
from wechatpy.replies import ArticlesReply

article = {'title': 'test', 'url': 'http://www.qq.com'}

r1 = ArticlesReply()
r1.add_article(article)
r2 = ArticlesReply()
self.assertTrue(r1.render() != r2.render())
6 changes: 4 additions & 2 deletions wechatpy/fields.py
Expand Up @@ -10,6 +10,8 @@
"""
from __future__ import absolute_import, unicode_literals
import base64
import copy

import six

from wechatpy.utils import to_text, to_binary, ObjectDict
Expand All @@ -25,8 +27,8 @@ def __get__(self, instance, instance_type=None):
if instance is not None:
value = instance._data.get(self.attr_name)
if value is None:
instance._data[self.attr_name] = self.field.default
value = self.field.default
value = copy.deepcopy(self.field.default)
instance._data[self.attr_name] = value
if isinstance(value, dict):
value = ObjectDict(value)
if value and not isinstance(value, (dict, list, tuple)) and \
Expand Down

0 comments on commit fc9eb80

Please sign in to comment.