From df0531566bade7163d2c9fe8aee78e6b6285665d Mon Sep 17 00:00:00 2001 From: Charles Leifer Date: Wed, 28 Mar 2018 14:45:12 -0500 Subject: [PATCH] 3.2.0 --- CHANGELOG.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ peewee.py | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c5daec2e..466688c32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,56 @@ releases, visit GitHub: https://github.com/coleifer/peewee/releases +## 3.2.0 + +The 3.2.0 release introduces a potentially backwards-incompatible change. The +only users affected will be those that have implemented custom `Field` types +with a user-defined `coerce` method. tl/dr: rename the coerce attribute to +adapt and you should be set. + +#### Field.coerce renamed to Field.adapt + +The `Field.coerce` method has been renamed to `Field.adapt`. The purpose of +this method is to convert a value from the application/database into the +appropriate Python data-type. For instance, `IntegerField.adapt` is simply the +`int` built-in function. + +The motivation for this change is to support adding metadata to any AST node +instructing Peewee to not coerce the associated value. As an example, consider +this code: + +```python + +class Note(Model): + id = AutoField() # autoincrementing integer primary key. + content = TextField() + +# Query notes table and cast the "id" to a string and store as "id_text" attr. +query = Note.select(Note.id.cast('TEXT').alias('id_text'), Note.content) + +a_note = query.get() +print((a_note.id_text, a_note.content)) + +# Prior to 3.2.0 the CAST is "un-done" because the value gets converted +# back to an integer, since the value is associated with the Note.id field: +(1, u'some note') # 3.1.7, e.g. -- "id_text" is an integer! + +# As of 3.2.0, CAST will automatically prevent the conversion of field values, +# which is an extension of a more general metadata API that can instruct Peewee +# not to convert certain values. +(u'1', u'some note') # 3.2.0 -- "id_text" is a string as expected. +``` + +If you have implemented custom `Field` classes and are using `coerce` to +enforce a particular data-type, you can simply rename the attribute to `adapt`. + +#### Other changes + +Old versions of SQLite do not strip quotation marks from aliased column names +in compound queries (e.g. UNION). Fixed in 3.2.0. + +[View commits](https://github.com/coleifer/peewee/compare/3.1.7...3.2.0) + ## 3.1.7 For all the winblows lusers out there, added an option to skip compilation of diff --git a/peewee.py b/peewee.py index ef25492d5..b8e1b00a5 100644 --- a/peewee.py +++ b/peewee.py @@ -54,7 +54,7 @@ mysql = None -__version__ = '3.1.7' +__version__ = '3.2.0' __all__ = [ 'AsIs', 'AutoField',