Possibly you are trying to use new ufl with the legacy dolfin.
Make sure you access ufl_legacy instead,
cf. Announcement: ufl_legacy and legacy dolfin
But if you are starting a new project, consider using dolfinx instead.
Let us know if ufl_legacy
fixes your issue.