docs: def _set_typeattr(typeattr, existing_ta = None):
      """
          Add or updsate a type attribute.
          If an existing type attribute is provided, then update.
  
          Checks are performed to ensure that the dimension provided on the
          type attr (not updateable) is the same as that on the referring attribute.
          The unit provided (stored on tattr) must conform to the dimension stored
          on the referring attribute (stored on tattr).
  
          This is done so that multiple tempaltes can all use the same attribute,
          but specify different units.
  
          If no attr_id is provided, but an attr_name and dimension are provided,
          then a new attribute can be created (or retrived) and used. I.e., no
          attribute ID must be specified if attr_name and dimension are specified.
  
          ***WARNING***
          Setting attribute ID to null means a new type attribute (and even a new attr)
          may be added, None are removed or replaced. To remove other type attrs, do it
          manually using delete_typeattr
      """
      if existing_ta is None:
          ta = TypeAttr(attr_id=typeattr.attr_id)
      else:
          ta = existing_ta
  
      ta.unit_id = typeattr.unit_id
      ta.type_id = typeattr.type_id
      ta.data_type = typeattr.data_type
  
      if hasattr(typeattr, 'default_dataset_id') and typeattr.default_dataset_id is not None:
          ta.default_dataset_id = typeattr.default_dataset_id
  
      ta.description        = typeattr.description
  
      ta.properties         = typeattr.get_properties()
  
      ta.attr_is_var        = typeattr.is_var if typeattr.is_var is not None else 'N'
  
      ta.data_restriction = _parse_data_restriction(typeattr.data_restriction)
  
      if typeattr.dimension_id is None:
          # All right. Check passed
          pass
      else:
  
          if typeattr.attr_id is not None and typeattr.attr_id > 0:
              # Getting the passed attribute, so we need to check consistency between attr dimension id and typeattr dimension id
              attr = ta.attr
  
              if attr is not None and attr.dimension_id is not None and attr.dimension_id != typeattr.dimension_id or \
                 attr is not None and attr.dimension_id is not None:
                  # In this case there is an inconsistency between attr.dimension_id and typeattr.dimension_id
                  raise HydraError("Cannot set a dimension on type attribute which "
                                  "does not match its attribute. Create a new attribute if "
                                  "you want to use attribute %s with dimension_id %s"%
                                  (attr.name, typeattr.dimension_id))
          elif typeattr.attr_id is None and typeattr.name is not None:
              # Getting/creating the attribute by typeattr dimension id and typeattr name
              # In this case the dimension_id "null"/"not null" status is ininfluent
              attr = _get_attr_by_name_and_dimension(typeattr.name, typeattr.dimension_id)
  
              ta.attr_id = attr.id
              ta.attr = attr
  
  
      _check_dimension(ta)
  
      if existing_ta is None:
          log.debug("Adding ta to DB")
          db.DBSession.add(ta)
  
      return ta