Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolved error handling in sql_translator #697 #703

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Replaced entity with getter (#652)
- Resolved TODO in Dockerfile (#680)
- Resolved TODO at src/reporter/tests/test_timescale_types.py (#667)
- Resolved TODO at src/translator/sql_translator.py (#697)

### Bug fixes

Expand Down
9 changes: 3 additions & 6 deletions src/translators/sql_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,12 @@ def _insert_entity_rows(self, table_name: str, col_names: List[str],
stmt = f"insert into {table_name} ({col_list}) values ({placeholders})"
try:
start_time = datetime.now()
res_list = []

for batch in to_insert_batches(rows):
res = self.cursor.executemany(stmt, batch)
# new version of crate does not bomb anymore when
# something goes wrong in multi entries
# simply it returns -2 for each row that have an issue
# TODO: improve error handling.
# using batches, we don't need to fail the whole set
# but only failing batches.
res_list.append(res)
for res in res_list:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach will only work for Crate, not Timescale which I think throws an exception instead. In general, what to do here will depend on the database at hand, so we should actually push this code down to the translator subclasses.

if isinstance(res, list):
for i in range(len(res)):
if res[i]['rowcount'] < 0:
Expand Down