Skip to content

Commit

Permalink
Move pre-commit checker into row converter
Browse files Browse the repository at this point in the history
  • Loading branch information
aleh-rymasheuski committed Jun 28, 2018
1 parent 48a844b commit d6b8361
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
15 changes: 0 additions & 15 deletions src/ggrc/converters/base_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from ggrc.utils import list_chunks
from ggrc.converters import errors
from ggrc.converters import get_shared_unique_rules
from ggrc.converters import pre_commit_checks
from ggrc.converters import base_row
from ggrc.converters.import_helper import get_column_order
from ggrc.converters.import_helper import get_object_column_definitions
Expand Down Expand Up @@ -506,20 +505,6 @@ def _store_revision_ids(self, event):
if event:
self.revision_ids.extend(revision.id for revision in event.revisions)

@staticmethod
def _check_object(row_converter):
"""Check object if it has any pre commit checks.
The check functions can mutate the row_converter object and mark it
to be ignored if there are any errors detected.
Args:
row_converter: Row converter for the row we want to check.
"""
checker = pre_commit_checks.CHECKS.get(type(row_converter.obj).__name__)
if checker and callable(checker):
checker(row_converter)

@staticmethod
def send_collection_post_signals(new_objects):
"""Send bulk create pre-commit signals."""
Expand Down
16 changes: 15 additions & 1 deletion src/ggrc/converters/base_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ggrc import db
from ggrc.converters import errors
from ggrc.converters import get_importables
from ggrc.converters import pre_commit_checks
from ggrc.login import get_current_user_id
from ggrc.models import all_models
from ggrc.models.exceptions import StatusValidationError
Expand Down Expand Up @@ -243,7 +244,7 @@ def process_row(self):
return
self.update_new_obj_cache()
self.setup_object()
self.block_converter._check_object(self)
self.check_object()
try:
if self.ignore and self.obj in db.session:
db.session.expunge(self.obj)
Expand All @@ -255,6 +256,19 @@ def process_row(self):
self.setup_secondary_objects()
self.commit_object()

def check_object(self):
"""Check object if it has any pre commit checks.
The check functions can mutate the row_converter object and mark it
to be ignored if there are any errors detected.
Args:
row_converter: Row converter for the row we want to check.
"""
checker = pre_commit_checks.CHECKS.get(type(self.obj).__name__)
if checker and callable(checker):
checker(self)

def flush_object(self):
"""Flush dirty data related to the current row."""
if self.block_converter.converter.dry_run or self.ignore:
Expand Down

0 comments on commit d6b8361

Please sign in to comment.