Facing an error in dimension matching

here I try to define boundary function for all faces except y=2, and the solution is defined in such a way it take a function at y=2 face except all faces

from dolfin import *
set_log_level(LogLevel.ERROR)
nx=32
mesh = UnitCubeMesh(nx,nx,nx)
# Define Function Spaces
V = VectorElement("CG", mesh.ufl_cell(), 2)
W= FiniteElement("CG", mesh.ufl_cell(), 1)
R = FiniteElement("Real", mesh.ufl_cell(), 0)
me = MixedElement([V, W, R])
Z= FunctionSpace(mesh,me)
tol=1E14
def boundary(x, on_boundary):
    return on_boundary and (near(x[0],0,tol) or near(x[0],2,tol) or near(x[1],0,tol) or near(x[2],0,tol) or near(x[2],2,tol))
# Define Test and trial function
up = Function(Z)
u, p, rho  = split(up)
v, q, lamda = TestFunctions(Z)

class BoundaryCondition(UserExpression):
    def eval(self, values, x):
        if near(x[1], 2.0) and 0.0 <= x[0] <= 2.0 and 0.0 <= x[2] <= 2.0:
            values[0] = x[0]*x[0]*(2-x[0])*(2-x[0])*x[2]*x[2]*(2-x[2])*(2-x[2])
            values[1] = 0.0
            values[2] = 0.0
        else:
            values[0] = 0.0
            values[1] = 0.0
            values[2] = 0.0
    
    def value_shape(self):
        return (3,)

# Example usage
u_exact = BoundaryCondition(degree=2)
             
p_exact = Expression('0', domain=mesh, degree=2)
f = -div(grad(u_exact))+grad(p_exact)+grad(u_exact)*u_exact

error:

raceback (most recent call last):
  File "/home/ayush/LID_DRIVEN_3D.py", line 37, in <module>
    f = -div(grad(u_exact))+grad(p_exact)+grad(u_exact)*u_exact
  File "/usr/lib/python3/dist-packages/ufl/operators.py", line 370, in grad
    return Grad(f)
  File "/usr/lib/python3/dist-packages/ufl/differentiation.py", line 147, in __init__
    self._dim = find_geometric_dimension(f)
  File "/usr/lib/python3/dist-packages/ufl/domain.py", line 376, in find_geometric_dimension
    error("Cannot determine geometric dimension from expression.")
  File "/usr/lib/python3/dist-packages/ufl/log.py", line 158, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Cannot determine geometric dimension from expression.

If you search for this error message on the forum, you find many similar questions. See for instance; Compute grad of UserExpression - #2 by VKTR