Django – Cannot make a celery worker and test transactions on test file without “You can’t execute queries until the end of the ‘atomic’ block.” error

Soo, here’s the deal, Im creating a test in order to check if an improvement a made for performance is working or not, the improvements consists in making some signals logic an async task instead of an async process, I wanted to test this out but when I manually create a celery worker I get the

django.db.transaction.TransactionManagementError: An error occurred in the current transaction. You can’t execute queries until the end of the ‘atomic’ block.

To have more context.. I’m avoiding creating a worker from the start because the pipeline does not use redis by default, or at least it avoids the celery creation, so I need to make one manually, but when I create the service I get the error

    def test_delete_optimal_deletion_time(self):
    """
    Verifies that the `deletion logic` is under an acceptable
    running time.
    :return:
    """
    # ... non-relevant code 
   # Start Celery worker in a separate context to avoid nested atomic transactions
    with start_worker(celery_app, perform_ping_check=False):
        data_delete_start = time.time()
        og_org.delete()
        data_delete_end = time.time()
        data_total_test_end = time.time()
        data_total_test_time = data_total_test_end - data_total_test_start
        data_delete_time = data_delete_end - data_delete_start
        print("time to create test data: ", data_creation_time)
        print("time to delete test data: ", data_delete_time)
        print("time to run all test data: ", data_total_test_time)
        print("settings.CELERY_TASK_ALWAYS_EAGER: ", settings.CELERY_TASK_ALWAYS_EAGER)

this line is the “root” crash

            og_org.delete()

this is because og_org’s delete method uses transaction.atomic to prevent deadlocks,
My theory is that the “with” define in order to use the agent acts as a try catch, which in newer iterations of django counts as an atomic transaction.. therefore the error, I haven’t been able to find a work around for this…

for some more context this is the delete method of og_org instance:

def delete(self, *args, **kwargs):
    with transaction.atomic():
        return super().delete(*args, **kwargs)

things I’ve tried

  1. wrapping this up in another atomic transaction
  2. defining the celery worker in the class setup
  3. trying to ran this og_org.delete() as a separate task outside the with
  4. tried to do it with start_worker….
    pass
  5. tried a bypass with he pytest library

I know the most simple solution would be to update some local_settings configurations and allow the agent creation at the beginning of the app creation for the tests and not just for the application itself, but I’m trying to leave this as a last resort. Any help is appreciated

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật