<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def load_preferences(session, config, valid_paths, cull_disabled=False, openid=None, cull_backends=None):
 """ Every rule for every filter for every context for every user. Any preferences in the DB that are for contexts that are disabled in the config are omitted here. If the `openid` argument is None, then this is an expensive query that loads, practically, the whole database. However, if an openid string is submitted, then only the preferences of that user are returned (and this is less expensive). """


    cull_backends = cull_backends or []

    query = session.query(fmn.lib.models.Preference)

    if openid:
        query = query.filter(fmn.lib.models.Preference.openid==openid)

    preferences = query.all()
    return [
        preference.__json__(reify=True)
        for preference in preferences
        if (
            preference.context.name in config['fmn.backends']
            and preference.context.name not in cull_backends
            and (not cull_disabled or preference.enabled)
        )
    ]