If you have issues make sure that you are using the ufl-legacy package with legacy fenics.
The new ufl (without the legacy postfix) is meant to work with dolfinx not dolfin (fenics).
At the top of the program you need to overload the ufl with ufl-legacy like this e.g.:
from fenics import *
import ufl_legacy as ufl
# your FEM code follows