Skip to content

Commit 91dadf4

Browse files
committed
Refs #351, make none_as_none default and prepare 0.8 release
1 parent 3367ab4 commit 91dadf4

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Contributors
2828
* Denys Badzo <[email protected]>
2929
* Pavol Vargovcik <[email protected]>
3030
* Mykyta Holubakha <[email protected]>
31+
3132

3233

3334
Special thanks to my wife Daisy and her outsourcing company `DecentFoX Studio`_,

HISTORY.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,61 @@
22
History
33
=======
44

5+
GINO 0.8
6+
--------
7+
8+
This is also version 1.0 release candidate.
9+
10+
Migrating to GINO 0.8
11+
^^^^^^^^^^^^^^^^^^^^^
12+
13+
1. contextvars
14+
""""""""""""""
15+
16+
We introduced aiocontextvars_ 0.2.0 which is revamped to be compatible with
17+
PEP-567 without manual interference by a few simple implicit patches. To
18+
upgrade to GINO 0.8, please remove the ``enable_inherit()`` or
19+
``disable_inherit()`` calls, because they are the default behavior now thus
20+
no longer exist. However, you'll need to confirm that the event loop in use is
21+
always created **after** importing ``gino`` or ``aiocontextvars``, or the patch
22+
won't work correctly.
23+
24+
There is nothing to worry about in Python 3.7.
25+
26+
2. none_as_none
27+
"""""""""""""""
28+
29+
When GINO tries to load a row with all ``NULL`` values into an instance, it
30+
will now by default return ``None`` instead of an instance with all ``None``
31+
attributes. To recover the default behavior of 0.7, please specify
32+
``none_as_none(False)`` in affected model loader.
33+
34+
This is especially applicable to relationship sub-loaders - if the sub-loader
35+
found it all ``NULL``, no instance will be set to parent instance. For
36+
example::
37+
38+
child = await Child.load(parent=Parent).query.gino.first()
39+
40+
If ``child.parent_id`` is ``NULL`` in database, then the ``child`` instance
41+
won't be called with any ``setattr(child, 'parent', ...)`` at all. (If you need
42+
``child.parent == None`` in this case, consider setting default value
43+
``parent = None`` in child model.)
44+
45+
Please note, it is deprecated to disable ``none_as_none``, and disabling will
46+
be removed in GINO 1.0.
47+
48+
0.8.0 (2018-00-00)
49+
^^^^^^^^^^^^^^^^^^
50+
51+
* Welcome Tony Wang to the maintenance team (#335)
52+
* Allowed custom column names (#261 #297)
53+
* Allowed column instance in ``model.load()`` (Contributed by Jekel in #323)
54+
* [Breaking] Upgraded to aiocontextvars 0.2.0 (#333)
55+
* Fixed bug that the same empty stack is shared between sub-tasks (#313 #334)
56+
* [Breaking] Made ``none_as_none()`` the default behavior (#351)
57+
* Bug fixes and docs update
58+
59+
560
GINO 0.7
661
--------
762

gino/loader.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,11 @@ def __init__(self, model, *columns, **extras):
7676
self.extras = dict((key, self.get(value))
7777
for key, value in extras.items())
7878
self.on_clause = None
79-
self._none_as_none = None
79+
self._none_as_none = True
8080

8181
def _do_load(self, row, *, none_as_none=None):
8282
if none_as_none is None:
8383
none_as_none = self._none_as_none
84-
if none_as_none is None:
85-
warnings.warn(
86-
'The none_as_none feature will be enabled by default in 0.8',
87-
DeprecationWarning)
8884
values = dict((c.name, row[c]) for c in self.columns if c in row)
8985
if none_as_none and all((v is None) for v in values.values()):
9086
return None
@@ -154,7 +150,7 @@ def distinct(self, *columns):
154150
def none_as_none(self, enabled=True):
155151
if not enabled:
156152
warnings.warn(
157-
'The none_as_none feature will be always enabled in 0.9',
153+
'The none_as_none feature will be always enabled in 1.0',
158154
PendingDeprecationWarning)
159155
self._none_as_none = enabled
160156
return self

tests/test_loader.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,21 @@ async def test_distinct_none(bind):
235235
u = await User.create()
236236

237237
query = User.outerjoin(Team).select().where(User.id == u.id)
238-
loader = User.load(team=Team)
238+
loader = User.load(team=Team.none_as_none(False))
239239

240+
# TODO: this should fail in 1.0, please remove by then
240241
u = await query.gino.load(loader).first()
241242
assert u.team.id is None
242243

244+
query = User.outerjoin(Team).select().where(User.id == u.id)
245+
loader = User.load(team=Team)
246+
247+
u = await query.gino.load(loader).first()
248+
assert not hasattr(u, 'team')
249+
250+
u = await User.load(team=Team).query.where(User.id == u.id).gino.first()
251+
assert not hasattr(u, 'team')
252+
243253
query = User.outerjoin(Team).select().where(User.id == u.id)
244254
loader = User.load(team=Team.distinct(Team.id))
245255

0 commit comments

Comments
 (0)