'Broke out guts of update_item for short-circuited internal use only'

def _update_item_from_fields(self, user_id, course_key, block_key, partitioned_fields, definition_locator, allow_not_found, force, asides=None, **kwargs):

    with self.bulk_operations(course_key):
        if (allow_not_found and isinstance(block_key.id, (LocalId, NoneType))):
            fields = {}
            for subfields in partitioned_fields.itervalues():
                fields.update(subfields)
            return self.create_item(user_id, course_key, block_key.type, fields=fields, asides=asides, force=force)
        original_structure = self._lookup_course(course_key).structure
        index_entry = self._get_index_if_valid(course_key, force)
        original_entry = self._get_block_from_structure(original_structure, block_key)
        if (original_entry is None):
            if allow_not_found:
                fields = {}
                for subfields in partitioned_fields.itervalues():
                    fields.update(subfields)
                return self.create_item(user_id, course_key, block_key.type, block_id=block_key.id, fields=fields, asides=asides, force=force)
            else:
                raise ItemNotFoundError(course_key.make_usage_key(block_key.type, block_key.id))
        is_updated = False
        definition_fields = partitioned_fields[Scope.content]
        if (definition_locator is None):
            definition_locator = DefinitionLocator(original_entry.block_type, original_entry.definition)
        if definition_fields:
            (definition_locator, is_updated) = self.update_definition_from_data(course_key, definition_locator, definition_fields, user_id)
        settings = partitioned_fields[Scope.settings]
        settings = self._serialize_fields(block_key.type, settings)
        if (not is_updated):
            is_updated = self._compare_settings(settings, original_entry.fields)
        if partitioned_fields.get(Scope.children, {}):
            serialized_children = [BlockKey.from_usage_key(child) for child in partitioned_fields[Scope.children]['children']]
            is_updated = (is_updated or (original_entry.fields.get('children', []) != serialized_children))
            if is_updated:
                settings['children'] = serialized_children
        asides_data_to_update = None
        if asides:
            (asides_data_to_update, asides_updated) = self._get_asides_to_update_from_structure(original_structure, block_key, asides)
        else:
            asides_updated = False
        if (is_updated or asides_updated):
            new_structure = self.version_structure(course_key, original_structure, user_id)
            block_data = self._get_block_from_structure(new_structure, block_key)
            block_data.definition = definition_locator.definition_id
            block_data.fields = settings
            if asides_updated:
                block_data.asides = asides_data_to_update
            new_id = new_structure['_id']
            block_data.edit_info.source_version = None
            self.version_block(block_data, user_id, new_id)
            self.update_structure(course_key, new_structure)
            if (index_entry is not None):
                self._update_search_targets(index_entry, definition_fields)
                self._update_search_targets(index_entry, settings)
                if isinstance(course_key, LibraryLocator):
                    course_key = LibraryLocator(org=index_entry['org'], library=index_entry['course'], branch=course_key.branch, version_guid=new_id)
                else:
                    course_key = CourseLocator(org=index_entry['org'], course=index_entry['course'], run=index_entry['run'], branch=course_key.branch, version_guid=new_id)
                self._update_head(course_key, index_entry, course_key.branch, new_id)
            elif isinstance(course_key, LibraryLocator):
                course_key = LibraryLocator(version_guid=new_id)
            else:
                course_key = CourseLocator(version_guid=new_id)
            if isinstance(course_key, LibraryLocator):
                self._flag_library_updated_event(course_key)
            new_locator = course_key.make_usage_key(block_key.type, block_key.id)
            return self.get_item(new_locator, **kwargs)
        else:
            return None
