Skip to content

Commit

Permalink
Merge pull request #263 from cinarizasyon/dev-4
Browse files Browse the repository at this point in the history
Mutable default method arguments fixed.
  • Loading branch information
josephmancuso authored Dec 8, 2020
2 parents 071a566 + b7543b6 commit e0a7ed3
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 44 deletions.
8 changes: 4 additions & 4 deletions src/masoniteorm/collection/Collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class Collection:
"""Wraps various data types to make working with them easier."""

def __init__(self, items=[]):
self._items = items
def __init__(self, items=None):
self._items = items or []
self.__appends__ = []

def take(self, number: int):
Expand Down Expand Up @@ -299,9 +299,9 @@ def _serialize(item):

return list(map(_serialize, self))

def add_relation(self, result={}):
def add_relation(self, result=None):
for model in self._items:
model.add_relations(result)
model.add_relations(result or {})

return self

Expand Down
8 changes: 4 additions & 4 deletions src/masoniteorm/connections/MSSQLConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def __init__(
port=None,
password=None,
prefix=None,
options={},
full_details={},
options=None,
full_details=None,
name=None,
):

Expand All @@ -38,8 +38,8 @@ def __init__(
self.user = user
self.password = password
self.prefix = prefix
self.full_details = full_details
self.options = options
self.full_details = full_details or {}
self.options = options or {}
self._cursor = None
self.transaction_level = 0
self.open = 0
Expand Down
8 changes: 4 additions & 4 deletions src/masoniteorm/connections/MySQLConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def __init__(
port=None,
password=None,
prefix=None,
options={},
full_details={},
options=None,
full_details=None,
name=None,
):
self.host = host
Expand All @@ -36,8 +36,8 @@ def __init__(
self.user = user
self.password = password
self.prefix = prefix
self.full_details = full_details
self.options = options
self.full_details = full_details or {}
self.options = options or {}
self._cursor = None
self.open = 0
self.transaction_level = 0
Expand Down
8 changes: 4 additions & 4 deletions src/masoniteorm/connections/PostgresConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def __init__(
port=None,
password=None,
prefix=None,
options={},
full_details={},
options=None,
full_details=None,
name=None,
):

Expand All @@ -38,8 +38,8 @@ def __init__(
self.user = user
self.password = password
self.prefix = prefix
self.full_details = full_details
self.options = options
self.full_details = full_details or {}
self.options = options or {}
self._cursor = None
self.transaction_level = 0
self.open = 0
Expand Down
8 changes: 4 additions & 4 deletions src/masoniteorm/connections/SQLiteConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(
port=None,
password=None,
prefix=None,
full_details={},
options={},
full_details=None,
options=None,
name=None,
):
self.host = host
Expand All @@ -36,8 +36,8 @@ def __init__(
self.user = user
self.password = password
self.prefix = prefix
self.full_details = full_details
self.options = options
self.full_details = full_details or {}
self.options = options or {}
self._cursor = None
self.transaction_level = 0
self.open = 0
Expand Down
4 changes: 2 additions & 2 deletions src/masoniteorm/migrations/Migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ def rollback_all(self):

self.delete_migrations(ran_migrations)

def delete_migrations(self, migrations=[]):
return self.migration_model.where_in("migration", migrations).delete()
def delete_migrations(self, migrations=None):
return self.migration_model.where_in("migration", migrations or []).delete()

def delete_last_batch(self):
return self.migration_model.where(
Expand Down
8 changes: 5 additions & 3 deletions src/masoniteorm/models/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def add_relation(self, relations):
return self

@classmethod
def hydrate(cls, result, relations={}):
def hydrate(cls, result, relations=None):
"""Takes a result and loads it into a model
Args:
Expand All @@ -255,6 +255,8 @@ def hydrate(cls, result, relations={}):
[type]: [description]
"""

relations = relations or {}

if result is None:
return None

Expand Down Expand Up @@ -307,7 +309,7 @@ def new_collection(cls, data):
return Collection(data)

@classmethod
def create(cls, dictionary={}, query=False, **kwargs):
def create(cls, dictionary=None, query=False, **kwargs):
"""Creates new records based off of a dictionary as well as data set on the model
such as fillable values.
Expand All @@ -333,7 +335,7 @@ def create(cls, dictionary={}, query=False, **kwargs):

return cls.builder.create(dictionary)

def serialize(self, serialized_dictionary={}):
def serialize(self, serialized_dictionary=None):
"""Takes the data as a model and converts it into a dictionary
Args:
Expand Down
20 changes: 13 additions & 7 deletions src/masoniteorm/query/QueryBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def __init__(
connection="default",
connection_class=None,
table=None,
connection_details={},
connection_details=None,
connection_driver="default",
model=None,
scopes={},
scopes=None,
dry=False,
):
"""QueryBuilder initializer
Expand All @@ -57,9 +57,9 @@ def __init__(
self.connection = connection
self.connection_class = connection_class
self._connection = None
self._connection_details = connection_details
self._connection_details = connection_details or {}
self._connection_driver = connection_driver
self._scopes = scopes
self._scopes = scopes or {}
self._eager_relation = EagerRelations()
if model:
self._global_scopes = model._global_scopes
Expand Down Expand Up @@ -352,7 +352,7 @@ def select_raw(self, string):
def get_processor(self):
return self.connection_class.get_default_post_processor()()

def create(self, creates={}, query=False, id_key="id", **kwargs):
def create(self, creates=None, query=False, id_key="id", **kwargs):
"""Specifies a dictionary that should be used to create new values.
Arguments:
Expand Down Expand Up @@ -612,7 +612,7 @@ def not_between(self, column: str, low: [str, int], high: [str, int]):
self._wheres += (BetweenExpression(column, low, high, equality="NOT BETWEEN"),)
return self

def where_in(self, column, wheres=[]):
def where_in(self, column, wheres=None):
"""Specifies where a column contains a list of a values.
Arguments:
Expand All @@ -624,6 +624,9 @@ def where_in(self, column, wheres=[]):
Returns:
self
"""

wheres = wheres or []

if not wheres:
self._wheres += ((QueryExpression(0, "=", 1, "value_equals")),)

Expand Down Expand Up @@ -714,7 +717,7 @@ def where_has(self, relationship, callback):
return self
# return self.owner.where_has(*args, **kwargs)

def where_not_in(self, column, wheres=[]):
def where_not_in(self, column, wheres=None):
"""Specifies where a column does not contain a list of a values.
Arguments:
Expand All @@ -726,6 +729,9 @@ def where_not_in(self, column, wheres=[]):
Returns:
self
"""

wheres = wheres or []

if isinstance(wheres, QueryBuilder):
self._wheres += (
(QueryExpression(column, "NOT IN", SubSelectExpression(wheres))),
Expand Down
8 changes: 4 additions & 4 deletions src/masoniteorm/query/grammars/BaseGrammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ def __init__(
wheres=(),
limit=False,
offset=False,
updates={},
updates=None,
aggregates=(),
order_by=(),
group_by=(),
joins=(),
having=(),
connection_details={},
connection_details=None,
):
self._columns = columns
self.table = table
self.database = database
self._wheres = wheres
self._limit = limit
self._offset = offset
self._updates = updates
self._updates = updates or {}
self._aggregates = aggregates
self._order_by = order_by
self._group_by = group_by
self._joins = joins
self._having = having
self._connection_details = connection_details
self._connection_details = connection_details or {}
self._column = None

self._bindings = ()
Expand Down
3 changes: 2 additions & 1 deletion src/masoniteorm/relationships/HasMany.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def apply_query(self, foreign, owner):

return result

def get_related(self, relation, eagers=[]):
def get_related(self, relation, eagers=None):
eagers = eagers or []
builder = self.get_builder().with_(eagers)
if isinstance(relation, Collection):
return builder.where_in(
Expand Down
4 changes: 3 additions & 1 deletion src/masoniteorm/schema/Blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def double(self, column, nullable=False):
self._last_column = self.table.add_column(column, "double", nullable=nullable)
return self

def enum(self, column, options=[], nullable=False):
def enum(self, column, options=None, nullable=False):
"""Sets a column to be the enum representation for the table.
Arguments:
Expand All @@ -285,6 +285,8 @@ def enum(self, column, options=[], nullable=False):
Returns:
self
"""

options = options or []
new_options = ""
for option in options:
new_options += "'{}',".format(option)
Expand Down
4 changes: 2 additions & 2 deletions src/masoniteorm/schema/Constraint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Constraint:
def __init__(self, name, constraint_type, columns=[]):
def __init__(self, name, constraint_type, columns=None):
self.name = name
self.constraint_type = constraint_type
self.columns = columns
self.columns = columns or []
4 changes: 2 additions & 2 deletions src/masoniteorm/schema/Schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(
connection_class=None,
platform=None,
grammar=None,
connection_details={},
connection_details=None,
connection_driver=None,
):
self._dry = dry
Expand All @@ -25,7 +25,7 @@ def __init__(
self._connection = None
self.grammar = grammar
self.platform = platform
self.connection_details = connection_details
self.connection_details = connection_details or {}
self._connection_driver = connection_driver
self._blueprint = None
self._sql = None
Expand Down
4 changes: 2 additions & 2 deletions src/masoniteorm/schema/Table.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def add_column(
self.added_columns.update({name: column})
return column

def add_constraint(self, name, constraint_type, columns=[]):
def add_constraint(self, name, constraint_type, columns=None):
self.added_constraints.update(
{name: Constraint(name, constraint_type, columns=columns)}
{name: Constraint(name, constraint_type, columns=columns or [])}
)

def add_foreign_key(self, column, table=None, foreign_column=None):
Expand Down

0 comments on commit e0a7ed3

Please sign in to comment.