Skip to content

Commit

Permalink
Fix bugs introduced in object instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
billyrrr committed Nov 11, 2019
1 parent 6b01adc commit 68a847a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
18 changes: 9 additions & 9 deletions flask_boiler/firestore_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class FirestoreObjectClsFactory(ClsFactory):

class FirestoreObjectMixin:

@classmethod
def new(cls, doc_ref=None, with_dict=None, **kwargs):
if doc_ref is None:
raise ValueError
if with_dict is not None:
obj = cls.from_dict(d=with_dict, doc_ref=doc_ref)
else:
obj = cls(doc_ref=doc_ref, **kwargs)
return obj
# @classmethod
# def new(cls, doc_ref=None, with_dict=None, **kwargs):
# if doc_ref is None:
# raise ValueError
# if with_dict is not None:
# obj = cls.from_dict(d=with_dict, doc_ref=doc_ref)
# else:
# obj = cls(doc_ref=doc_ref, **kwargs)
# return obj

def get_firestore_ref(self):
warnings.warn("Please use .doc_ref instead. ", DeprecationWarning)
Expand Down
5 changes: 2 additions & 3 deletions flask_boiler/primary_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ def get_schema_cls(cls):
else:
return cls._schema_cls

def __init__(self, doc_id=None, doc_ref=None):
def __init__(self, doc_id=None, doc_ref=None, **kwargs):
if doc_ref is None:
doc_ref = self._doc_ref_from_id(doc_id=doc_id)

super().__init__(doc_ref=doc_ref)
super().__init__(doc_ref=doc_ref, **kwargs)

@property
def doc_id(self):
Expand Down
6 changes: 1 addition & 5 deletions flask_boiler/serializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def new(cls, allow_default=True, **kwargs):

fd = cls._get_fields() # Calls classmethod

field_keys = {key for key, field in fd.items()}
field_keys = {key for key, field in fd.items() if not field.dump_only}
kwargs_keys = set(kwargs.keys())

required_keys = {val for key, val in fd.items() if val.required}
Expand Down Expand Up @@ -285,10 +285,6 @@ def __init__(self, _with_dict=None, **kwargs):

super().__init__(**kwargs)

@classmethod
def from_dict(cls, d, **kwargs):
return cls.new({**d, **kwargs})


class Mutable(BaseRegisteredModel,
Schemed, Importable, NewMixin, Exportable):
Expand Down

0 comments on commit 68a847a

Please sign in to comment.