Skip to content

Commit

Permalink
Modified add_field in model, fixed collections import.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusklang committed Jun 12, 2020
1 parent 71d5a79 commit 7e093ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion py/docria/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,12 +1257,13 @@ def _update_default_values(self):
self._default_values = {field: typedef.default() for field, typedef in self.schema.fields.items() if
typedef.default() is not None}

def add_field(self, name: str, type: "DataType"):
def add_field(self, name: str, type: "DataType", init_with_default=True):
"""
Add new field to the schema
:param name: name of the field
:param type: type of the field
:param init_with_default: set all existing nodes fields to default value
:raises SchemaValidationError if the field conflicts with existing field
"""
Expand All @@ -1272,6 +1273,11 @@ def add_field(self, name: str, type: "DataType"):
self._schema.add(name, type)
self._update_default_values()

# Set all current values to the default
defaultvalue = type.default()
for n in self:
n[name] = defaultvalue

def remove_field(self, name: str, leave_data=False)->bool:
"""
Remove existing field
Expand Down
2 changes: 1 addition & 1 deletion py/docria/storage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections import *
from .collections import *
from warnings import warn
warn("Deprecated: storage module has been renamed to collection, is forwarded for backwards compatability,"
" storage module will be removed in a future version.")

0 comments on commit 7e093ec

Please sign in to comment.