Remove transaction.atomic() from fixtures

This commit is contained in:
zandercymatics 2025-02-04 15:15:02 -07:00
parent 7c613a01f8
commit c2eacbfcdb
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
5 changed files with 26 additions and 42 deletions

View file

@ -30,7 +30,6 @@ class DomainFixture(DomainRequestFixture):
# Lumped under .atomic to ensure we don't make redundant DB calls.
# This bundles them all together, and then saves it in a single call.
try:
with transaction.atomic():
# Get the usernames of users created in the UserFixture
created_usernames = [user_data["username"] for user_data in UserFixture.ADMINS + UserFixture.STAFF]

View file

@ -84,11 +84,7 @@ class PortfolioFixture:
def load(cls):
"""Creates portfolios."""
logger.info("Going to load %s portfolios" % len(cls.PORTFOLIOS))
# Lumped under .atomic to ensure we don't make redundant DB calls.
# This bundles them all together, and then saves it in a single call.
try:
with transaction.atomic():
user = User.objects.all().last()
except Exception as e:
logger.warning(e)
@ -106,7 +102,6 @@ class PortfolioFixture:
continue
try:
with transaction.atomic():
portfolio = Portfolio(
creator=user,
organization_name=portfolio_data["organization_name"],

View file

@ -303,14 +303,7 @@ class DomainRequestFixture:
def load(cls):
"""Creates domain requests for each user in the database."""
logger.info("Going to load %s domain requests" % len(cls.DOMAINREQUESTS))
# Lumped under .atomic to ensure we don't make redundant DB calls.
# This bundles them all together, and then saves it in a single call.
# The atomic block will cause the code to stop executing if one instance in the
# nested iteration fails, which will cause an early exit and make it hard to debug.
# Comment out with transaction.atomic() when debugging.
try:
with transaction.atomic():
# Get the usernames of users created in the UserFixture
created_usernames = [user_data["username"] for user_data in UserFixture.ADMINS + UserFixture.STAFF]

View file

@ -34,8 +34,6 @@ class SuborganizationFixture:
def load(cls):
"""Creates suborganizations."""
logger.info(f"Going to load {len(cls.SUBORGS)} suborgs")
with transaction.atomic():
portfolios = cls._get_portfolios()
if not portfolios:
return

View file

@ -430,7 +430,6 @@ class UserFixture:
@classmethod
def load(cls):
with transaction.atomic():
cls.load_users(cls.ADMINS, "full_access_group", are_superusers=True)
cls.load_users(cls.STAFF, "cisa_analysts_group")