-
Notifications
You must be signed in to change notification settings - Fork 83
#88 Support the addition of new fields to an existing schema. #275
base: master
Are you sure you want to change the base?
Conversation
JonathanWylie
commented
Mar 15, 2016
- Especially ListFields and DictFields
- Especially ListFields and DictFields
I'm just not sure of the behavior where the data set in the |
(Also, it looks like your changes made the tests fail. Can you look into that?) |
OK so I have been writing loads of stuff to explain to you, and in the process I think I have got to the real crux of the problem. The architecture handles defaults in two different ways.
When a document is initialized, then all the defaults are hard written into the document, so you can see them in document._data, and those defaults will be written to the db when the document is stored. When a document is loaded from the database, then any missing defaults from the document are not hard written into the document. (My suggested fix changes that) It also handles defaults in Unfortunately it is hard to make that kind of defaulting work with this architecture. I had a go at bubbling up the sets which does work, but is a horrible hack, So I recommend removing the default handling in Incidentally there is a bug in I am going to go have a look at the tests see what's going on. I didn't realise we have a mix of doc tests and stand alone tests. |
To answer about your question about wrap itself.
|
…setting the default values for fields in the schema when wrapping data loaded from the DB. - Especially ListFields and DictFields
…ead of overloading the descriptor __get__ method. - The _get_ method should return values in python types, eg a date time is a datetime.datetime instance - The default values need to be in basic json types, eg [1,2,3] , {}, str, int which can be serialized to the doc - We don't need to get the default values in __get__ anymore because the defaults are set on initialisation of the mapping, or on wrap in a mapping.
I know understand the bug in
|
…ms. These aren't massive so it doesn't really matter.
- Especially ListFields and DictFields - The _to_json need to be idempotent to support string values coming from wraps, and python type values eg DateTime coming from user code.
OK so even though the tests pass, I came across another case where this solution doesn't work. So I went back to the old way of getting the defaults set. Now the tests pass, using the original solution. |
Wow, that's incredibly thorough! Thank you for really diving into this. In part, this is generating some more questions for me, so I hope you'll bear with me.
Does this make sense to you? Does it match what your changes do? As for the actual commits, I'd like to have a clean commit series with small commits moving the behavior to what it should be. Also, having extensive commit messages is great, but please keep the first line of the commit message at about ~70 characters, then add an empty line, then continue the story. I hope you still have time/energy to work on this! |
So yes you have understood pretty well what's going on. It seems bad to handle defaults in an inconsistent way. I think they should either always be lazy or always eager. When I was considering the pros and cons between them I think that the eager solution is better. This is because there are cases when you want to change a default only for new records, not for old one's. Which is almost impossible to do with a lazy default system. However with a eager default system, if you change the default, it's not that hard to update old records if you do want to change the defaults which have been written to old documents. Also: |
Okay, I agree that the eager behavior is better, I was just working through the pros and cons before. Could you clean up the commits a bit along the lines that I suggested? If not, I can do that. |
Yes I can clean it up. Just didn't want to do it before we had agreed the behavior you want. |
Sounds great! |
Hey, did you get a chance to work on this? If not, I'll just clean it up. :) |
Sorry I was really busy last week. |
Hey @JonathanWylie, do you think you'll have time in the near future to clean this up a little? If not, that's fine too, just let me know and I'll try to dig into it myself. |