'The only method in which obj.object_store_id may be None.'

def create(self, obj, **kwargs):

    if ((obj.object_store_id is None) or (not self.exists(obj, **kwargs))):
        if ((obj.object_store_id is None) or (obj.object_store_id not in self.weighted_backend_ids)):
            try:
                obj.object_store_id = random.choice(self.weighted_backend_ids)
            except IndexError:
                raise ObjectInvalid(('objectstore.create,    could    not    generate    obj.object_store_id:    %s,    kwargs:    %s' % (str(obj), str(kwargs))))
            _create_object_in_session(obj)
            log.debug(("Selected    backend    '%s'    for    creation    of    %s    %s" % (obj.object_store_id, obj.__class__.__name__, obj.id)))
        else:
            log.debug(("Using    preferred    backend    '%s'    for    creation    of    %s    %s" % (obj.object_store_id, obj.__class__.__name__, obj.id)))
        self.backends[obj.object_store_id].create(obj, **kwargs)
