pythonpython-3.xdjangodjango-signalsdjango-3.0

Signals don't work when outside MQTT script inserts data to database


I have django project and I have signals in model.py file. I created demo just to show what problem is


def func(sender, instance, created, **kwargs):
    
    try:
        if created:
           print("WORKED")
    except BaseException as e:
        import traceback
        print(traceback.format_exc())


post_save.connect(func, sender=MyTable,
                  dispatch_uid="IDDD")

When I insert data from admin panel, everything is OK, it prints,however, when I use simple script which inserts to MyTable by using psycopg, signal does not work, but data is saved to the table.


Solution

  • Solution:

    I inserted data through api, everything worked.