'Find all inheritable fields from all xblocks in the course which may define inheritable data'

def _compute_metadata_inheritance_tree(self, course_id):

    course_id = self.fill_in_run(course_id)
    query = SON([('_id.tag', 'i4x'), ('_id.org', course_id.org), ('_id.course', course_id.course), ('_id.category', {'$in': BLOCK_TYPES_WITH_CHILDREN})])
    if (self.get_branch_setting() == ModuleStoreEnum.Branch.published_only):
        query['_id.revision'] = None
    record_filter = {'_id': 1, 'definition.children': 1}
    for field_name in InheritanceMixin.fields:
        record_filter['metadata.{0}'.format(field_name)] = 1
    resultset = self.collection.find(query, record_filter)
    results_by_url = {}
    root = None
    for result in resultset:
        location = as_published(Location._from_deprecated_son(result['_id'], course_id.run))
        location_url = unicode(location)
        if (location_url in results_by_url):
            existing_children = results_by_url[location_url].get('definition', {}).get('children', [])
            additional_children = result.get('definition', {}).get('children', [])
            total_children = (existing_children + additional_children)
            results_by_url[location_url].setdefault('definition', {})['children'] = set(total_children)
        else:
            results_by_url[location_url] = result
        if (location.category == 'course'):
            root = location_url
    metadata_to_inherit = {}
    def _compute_inherited_metadata(url):
        '\n                                                Helper    method    for    computing    inherited    metadata    for    a    specific    location    url\n                                                '
        my_metadata = results_by_url[url].get('metadata', {})
        for child in results_by_url[url].get('definition', {}).get('children', []):
            if (child in results_by_url):
                new_child_metadata = copy.deepcopy(my_metadata)
                new_child_metadata.update(results_by_url[child].get('metadata', {}))
                results_by_url[child]['metadata'] = new_child_metadata
                metadata_to_inherit[child] = new_child_metadata
                _compute_inherited_metadata(child)
            else:
                metadata_to_inherit[child] = my_metadata.copy()
            metadata_to_inherit[child].setdefault('parent', {})[self.get_branch_setting()] = url
    if (root is not None):
        _compute_inherited_metadata(root)
    return metadata_to_inherit
