Trouble: activeSourcesSelectionModel() gives no active proxy

Hello dear Paraview developers!

I use

  vtkSMProxy* proxy = pqActiveObjects::instance().activeSourcesSelectionModel()->GetCurrentProxy();
  vtkSMSourceProxy* source_proxy = vtkSMSourceProxy::SafeDownCast(proxy);

to get the current active proxy and later perform some actions with that proxy (create filters, etc)

The problem is after these actions are performed, and I call this code again, source_proxy = nullptr

Could you help me with this problem, please?

Thank you very much

vtkSMProxySelectionModel is NOT a vtkSMSourceProxy