File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed
src/django_github_app/management/commands Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
1818
1919## [ Unreleased]
2020
21+ ### Fixed
22+
23+ - ` github import-app ` management command is now wrapped in an atomic transaction, in case any import steps fail.
24+
2125## [ 0.2.0]
2226
2327### Added
Original file line number Diff line number Diff line change 33from typing import Annotated
44from typing import Any
55
6+ from django .db import transaction
67from django_typer .management import Typer
78from typer import Option
89
@@ -34,7 +35,8 @@ def import_app(
3435 """
3536 Import an existing GitHub App to database Models.
3637 """
37- installation = Installation .objects .create (installation_id = installation_id )
38- installation .refresh_from_gh (account_type = type , account_name = name )
39- repository_data = installation .get_repos ()
40- Repository .objects .create_from_gh_data (repository_data , installation )
38+ with transaction .atomic ():
39+ installation = Installation .objects .create (installation_id = installation_id )
40+ installation .refresh_from_gh (account_type = type , account_name = name )
41+ repository_data = installation .get_repos ()
42+ Repository .objects .create_from_gh_data (repository_data , installation )
Original file line number Diff line number Diff line change @@ -80,3 +80,23 @@ def test_import_app_management_command(settings):
8080 len (installation .get_repos ())
8181 == Repository .objects .filter (installation = installation ).count ()
8282 )
83+
84+
85+ def test_import_app_transaction (settings , monkeypatch ):
86+ def mock_create_from_gh_data (* args , ** kwargs ):
87+ raise ValueError
88+
89+ monkeypatch .setattr (
90+ Repository .objects , "create_from_gh_data" , mock_create_from_gh_data
91+ )
92+
93+ with pytest .raises (ValueError ):
94+ import_app (
95+ type = settings .account_type ,
96+ name = settings .account_name ,
97+ installation_id = int (settings .installation_id ),
98+ )
99+
100+ assert not Installation .objects .filter (
101+ installation_id = settings .installation_id
102+ ).exists ()
You can’t perform that action at this time.
0 commit comments