Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(101)

Issue 6870063: Don't mutate default values for properties

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 10 months ago by Cd-MaN
Modified:
12 years, 10 months ago
Reviewers:
guido, GvR
CC:
appengine-ndb-discuss_googlegroups.com
Visibility:
Public.

Description

Don't mutate default values for properties

Patch Set 1 #

Total comments: 8

Patch Set 2 : Don't mutate default values for properties #

Total comments: 1

Patch Set 3 : Don't mutate default values for properties #

Total comments: 1

Patch Set 4 : Don't mutate default values for properties #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+38 lines, -0 lines) Patch
M ndb/model.py View 1 2 3 1 chunk +7 lines, -0 lines 0 comments Download
M ndb/model_test.py View 1 2 3 1 chunk +31 lines, -0 lines 2 comments Download

Messages

Total messages: 14
Cd-MaN
12 years, 10 months ago (2012-12-05 12:50:46 UTC) #1
guido
https://codereview.appspot.com/6870063/diff/1/ndb/model.py File ndb/model.py (right): https://codereview.appspot.com/6870063/diff/1/ndb/model.py#newcode1018 ndb/model.py:1018: if result is default and default is not None: ...
12 years, 10 months ago (2012-12-05 17:46:35 UTC) #2
Cd-MaN
https://codereview.appspot.com/6870063/diff/1/ndb/model.py File ndb/model.py (right): https://codereview.appspot.com/6870063/diff/1/ndb/model.py#newcode1019 ndb/model.py:1019: if isinstance(result, Model): Would it be better if model ...
12 years, 10 months ago (2012-12-05 17:50:48 UTC) #3
guido
https://codereview.appspot.com/6870063/diff/1/ndb/model.py File ndb/model.py (right): https://codereview.appspot.com/6870063/diff/1/ndb/model.py#newcode1019 ndb/model.py:1019: if isinstance(result, Model): On 2012/12/05 17:50:48, Cd-MaN wrote: > ...
12 years, 10 months ago (2012-12-05 18:02:33 UTC) #4
Cd-MaN
Hello, I uploaded a second patchset with the following changes: - it only targets *structed ...
12 years, 10 months ago (2012-12-06 22:44:34 UTC) #5
guido
Looks better, still one suggestion. Now I have to think about this more and decide ...
12 years, 10 months ago (2012-12-06 22:51:55 UTC) #6
guido
https://codereview.appspot.com/6870063/diff/7001/ndb/model.py File ndb/model.py (right): https://codereview.appspot.com/6870063/diff/7001/ndb/model.py#newcode2040 ndb/model.py:2040: result = type(default)._from_pb(default._to_pb()) I think you need to do ...
12 years, 10 months ago (2012-12-06 22:52:07 UTC) #7
Cd-MaN
Updated the patchset with the suggested verification. However, wouldn't such verification be better suited to ...
12 years, 10 months ago (2012-12-06 23:26:06 UTC) #8
guido
You're right, but that definitely requires more unittests (of the constructor). https://codereview.appspot.com/6870063/diff/13001/ndb/model.py File ndb/model.py (right): ...
12 years, 10 months ago (2012-12-06 23:36:01 UTC) #9
guido
FWIW, I no longer have a problem with fixing this. It's a bug. So let's ...
12 years, 10 months ago (2012-12-07 01:44:11 UTC) #10
Cd-MaN
Hello, I uploaded a new patchset with two changes: - I removed the verification for ...
12 years, 10 months ago (2012-12-07 19:35:19 UTC) #11
Cd-MaN
The part with type checking for the default values of (Local)StructuredProperty: http://codereview.appspot.com/6903051/
12 years, 10 months ago (2012-12-07 19:38:54 UTC) #12
GvR
https://codereview.appspot.com/6870063/diff/17001/ndb/model_test.py File ndb/model_test.py (right): https://codereview.appspot.com/6870063/diff/17001/ndb/model_test.py#newcode4505 ndb/model_test.py:4505: self.assertEqual(2, entity.container.other_value) I see. This is why you use ...
12 years, 10 months ago (2012-12-07 20:13:11 UTC) #13
Cd-MaN
12 years, 10 months ago (2012-12-13 19:09:58 UTC) #14
https://codereview.appspot.com/6870063/diff/17001/ndb/model_test.py File ndb/model_test.py (right): https://codereview.appspot.com/6870063/diff/17001/ndb/model_test.py#newcode4505 ndb/model_test.py:4505: self.assertEqual(2, entity.container.other_value) I have no concrete use-case for supporting this, it is more a "try not to break existing code" thing. I did a quick check and it indeed comes back as Value after a roundtrip from the datastore (you can still read other_value from it if you muck around with the internals or declare Value to be an Expando). In conclusion: I'm happy to remove this and use self._modelclass (and also use the more restrictive type(self._default) != modelclass in [1]) if you think that this property should be strictly enforced. [1] http://codereview.appspot.com/6903051/
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b