Skip to content

Refactor DBcore without changing behaviour#959

Merged
sampsyo merged 7 commits intobeetbox:masterfrom
geigerzaehler:dbcore-refactor
Sep 14, 2014
Merged

Refactor DBcore without changing behaviour#959
sampsyo merged 7 commits intobeetbox:masterfrom
geigerzaehler:dbcore-refactor

Conversation

@geigerzaehler
Copy link

This PR contains some of the refactoring from #919. It extends the Type API and clearly separates responsibilities. The new API allows us to remove a lot of similar code.

For a review I suggest to first look at the final types.py file and the changes in the model implementation, modulo the changes in 19d3ca8. This will get you an overview of the goal. Then each commit should be reviewed. The changes are atomic and should leave the behaviour of the program unchanged.

Thomas Scholtes added 7 commits September 14, 2014 16:13
Previously `normalize()` was used to convert values set by the model API
consumer and values received from the database. These are two
orthogonal uses.

The commit does not change behaviour since the `from_sql()` method uses
the `normalize()` implementation.
Instead of encoding the conversion behaviour in the model class (via
the `_bytes_keys` attribute) we define it on the type. This gives us
a more extensible interface and separates logic.

This should not change any behaviour (as one can see by closely staring
at the code).
We want to move common code into the base class with out changing the
behaviour of the default type.
Instead of implementing the `parse()` and `format()` methods and
setting the `null` attribute in subclasses, we set the `model_type`
field and the generic implementations of the two methods take care of
the rest.

Again: No change in behaviour!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo: looks like there are now two if value is None: cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just after posting this, I realized why you did this. My mistake—sorry for the noise!

@sampsyo
Copy link
Member

sampsyo commented Sep 14, 2014

This is all absolutely stellar stuff. ✨ I like all the changes; these do have a large impact on readability. And extra points for the nice organization into atomic commits. Woohoo!

I asked one question above, which is more relevant to the next stage in this process than this refactoring. I'd like to merge this now (I'm still working on #953 and it seems like a recipe for conflicts) and I'll make that one tiny bytes change.

Thanks again!

@sampsyo sampsyo merged commit fafc56c into beetbox:master Sep 14, 2014
sampsyo added a commit that referenced this pull request Sep 14, 2014
Refactor DBcore without changing behaviour
sampsyo added a commit that referenced this pull request Sep 14, 2014
@geigerzaehler
Copy link
Author

Should we just switch back to TEXT and use this stringly typed translation?

Yes, I think so. Since the user might change the type of a flexible attribute at will we should at least make the database schema consistent. Then we only need to deserialize strings. For now I updated the documentation to reflect the current state.

@sampsyo
Copy link
Member

sampsyo commented Sep 14, 2014

OK, sounds like a plan.

@geigerzaehler geigerzaehler deleted the dbcore-refactor branch September 14, 2014 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants