Skip to content

Commit

Permalink
Raise a more specific error when the model already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnVinyard committed Jun 24, 2017
1 parent 017e57f commit 9f9f598
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion featureflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.17.14'
__version__ = '1.18.14'

from model import BaseModel

Expand Down
12 changes: 10 additions & 2 deletions featureflow/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ class NoPersistenceSettingsError(Exception):
pass


class ModelExistsError(Exception):
"""
Error raised when a model has already been computed and persisted
"""
pass


class BaseModel(object):
__metaclass__ = MetaModel

Expand Down Expand Up @@ -95,8 +102,9 @@ def process(cls, raise_if_exists=False, **kwargs):
feature_key = feature.feature_key(_id, cls)
# check if that feature is already stored
if feature_key in cls.database:
raise ValueError(
'{_id} is already stored in the database'.format(**locals()))
raise ModelExistsError(
'{_id} is already stored in the database'.format(
**locals()))

graph = cls._build_extractor(_id)
graph.remove_dead_nodes(cls.features.itervalues())
Expand Down
4 changes: 2 additions & 2 deletions featureflow/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from extractor import NotEnoughData, Aggregator, Node, InvalidProcessMethod
from iteratornode import IteratorNode
from model import BaseModel, NoPersistenceSettingsError
from model import BaseModel, NoPersistenceSettingsError, ModelExistsError
from feature import Feature, JSONFeature, CompressedFeature
from data import *
from bytestream import ByteStream, ByteStreamFeature
Expand Down Expand Up @@ -804,7 +804,7 @@ class Document(BaseModel, settings):

Document.process(stream='humpty', _id='blah', raise_if_exists=True)
# processing the same id a second time should raise an error
self.assertRaises(ValueError, lambda: Document.process(
self.assertRaises(ModelExistsError, lambda: Document.process(
stream='humpty', _id='blah', raise_if_exists=True))

def test_can_have_multiple_producer_like_nodes(self):
Expand Down

0 comments on commit 9f9f598

Please sign in to comment.