Skip to content

Commit

Permalink
fix: on conflict do nothing (#1123)
Browse files Browse the repository at this point in the history
  • Loading branch information
long2ice committed May 8, 2022
1 parent aa3d511 commit 854998d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Added
Fixed
^^^^^
- `TimeField` for `MySQL` will return `datetime.timedelta` object instead of `datetime.time` object.
- Fix on conflict do nothing. (#1122)

0.19.0
------
Expand Down
1 change: 1 addition & 0 deletions tests/test_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async def test_bulk_create_uuidpk_in_transaction_fail(self):
async def test_bulk_create_ignore_conflicts(self):
name1 = UniqueName(name="name1")
name2 = UniqueName(name="name2")
await UniqueName.bulk_create([name1, name2])
await UniqueName.bulk_create([name1, name2], ignore_conflicts=True)
with self.assertRaises(IntegrityError):
await UniqueName.bulk_create([name1, name2])
2 changes: 1 addition & 1 deletion tortoise/backends/base/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _prepare_insert_statement(
.insert(*[self.parameter(i) for i in range(len(columns))])
)
if ignore_conflicts:
query = query.do_nothing()
query = query.on_conflict().do_nothing()
return query

async def _process_insert_result(self, instance: "Model", results: Any) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tortoise/backends/base_postgres/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _prepare_insert_statement(
if generated_fields:
query = query.returning(*generated_fields)
if ignore_conflicts:
query = query.do_nothing()
query = query.on_conflict().do_nothing()
return query

async def _process_insert_result(self, instance: Model, results: Optional[dict]) -> None:
Expand Down

0 comments on commit 854998d

Please sign in to comment.