r=polar.base_scalar(0) or r,theta=polar.base_scalars() should be added before definition of the metric g=....
r=polar.base_scalar(0)
r,theta=polar.base_scalars()
g=....
Please note that the definition of x and y x,y=symbols(...) should be moved before their use in relation_dict = {....
x,y=symbols(...)
relation_dict = {....