code: def initialize_object(B, res, row):
      
      B = get_backend()
      field_groups = FieldGroups(B.get_concrete(res))
  
      try:
          obj = B.get_object(B.get_concrete(res), row['id'])
      except B.object_missing_error(B.get_concrete(res)):
          tbl = B.get_concrete(res)
          obj = tbl()
  
      # Set attributes, refs
      for fname, field in field_groups['scalars'].items():
          value = row.get(fname, getattr(obj, fname, None))
          value = B.convert_field(obj.__class__, fname, value)
          setattr(obj, fname, value)
      # _debug('res, row: %s, %s', res, row)
  
      # Already-fetched, and id-only refs
      fetched, dangling = defaultdict(dict), defaultdict(set)
  
      # To handle subrows that might be shallow (id) or deep (dict)
      def _handle_subrow(R, subrow):
          if isinstance(subrow, dict):
              pk = subrow['id']
              fetched[R][pk] = subrow
          else:
              pk = subrow
              dangling[R].add(pk)
          return pk
  
      for fname, field in field_groups['one_refs'].items():
          fieldres = _field_resource(B, B.get_concrete(res), fname)
          key = field.column
          subrow = row.get(key)
          if subrow is None:  # e.g. use "org" if "org_id" is missing
              key = fname
              subrow = row[key]
          pk = _handle_subrow(fieldres, subrow)
          setattr(obj, key, pk)
  
      for fname, field in field_groups['many_refs'].items():
          fieldres = _field_resource(B, B.get_concrete(res), fname)
          pks = [
              _handle_subrow(fieldres, subrow) for subrow in row.get(fname, [])
          ]
  
      return obj, fetched, dangling
docs: Do a shallow initialization of an object
  
      Arguments:
          - row<dict>: dict of data like depth=1, i.e. many_refs are only ids