Skip to content

Commit

Permalink
Add deprecation warnings for get_object(), update_object(), create_ob…
Browse files Browse the repository at this point in the history
…ject(), delete_object()
  • Loading branch information
rudyryk committed Apr 19, 2016
1 parent 25c41b5 commit 164e9ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ TestModel.create_table(True)
TestModel.create(text="Yo, I can do it sync!")
database.close()

# Create async database manager:
# Create async models manager:

objects = peewee_async.Manager(database)

Expand Down
26 changes: 22 additions & 4 deletions peewee_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@
'Manager',
'PostgresqlDatabase',
'PooledPostgresqlDatabase',
'MySQLDatabase',
'PooledMySQLDatabase',

### Low level API ###

'execute',
'get_object',
'create_object',
'delete_object',
'update_object',
'count',
'scalar',
'atomic',
Expand All @@ -55,6 +53,10 @@

### Deprecated ###

'get_object',
'create_object',
'delete_object',
'update_object',
'sync_unwanted',
'UnwantedSyncQueryError',
]
Expand Down Expand Up @@ -399,6 +401,10 @@ def create_object(model, **data):
# - obj._set_pk_value()
# - obj._prepare_instance()
#
warnings.warn("delete_object() is deprecated, Manager.create() "
"should be used instead",
DeprecationWarning)

obj = model(**data)

pk = yield from insert(model.insert(**dict(obj._data)))
Expand All @@ -420,6 +426,10 @@ def get_object(source, *args):
:param args: lookup parameters
:return: model instance or raises ``peewee.DoesNotExist`` if object not found
"""
warnings.warn("get_object() is deprecated, Manager.get() "
"should be used instead",
DeprecationWarning)

if isinstance(source, peewee.Query):
query = source
model = query.model_class
Expand Down Expand Up @@ -447,6 +457,10 @@ def delete_object(obj, recursive=False, delete_nullable=False):
.. _Model.delete_instance(): http://peewee.readthedocs.org/en/latest/peewee/api.html#Model.delete_instance
"""
warnings.warn("delete_object() is deprecated, Manager.delete() "
"should be used instead",
DeprecationWarning)

# Here are private calls involved:
# - obj._pk_expr()
if recursive:
Expand Down Expand Up @@ -482,6 +496,10 @@ def update_object(obj, only=None):
# - obj._pk_expr()
# - obj._dirty.clear()
#
warnings.warn("delete_object() is deprecated, Manager.update() "
"should be used instead",
DeprecationWarning)

field_dict = dict(obj._data)
pk_field = obj._meta.primary_key

Expand Down

0 comments on commit 164e9ec

Please sign in to comment.