{"record":{"id":"a6a33827b2e2d113","repo":"celery/celery","slug":"cannot-mix-new-and-old-setting-keys-please-renam","errorCode":null,"errorMessage":"\nCannot mix new and old setting keys, please rename the\nfollowing settings to the new format:\n\n{renames}\n\n","messagePattern":"\nCannot mix new and old setting keys, please rename the\nfollowing settings to the new format:\n\n(.+?)\n\n","errorType":"validation","errorClass":"ImproperlyConfigured","httpStatus":null,"severity":"critical","filePath":"celery/app/utils.py","lineNumber":274,"sourceCode":"            info, left = _old_settings_info, is_in_new\n        if is_in_new and len(is_in_new) > len(is_in_old):\n            # Majority of the settings are new\n            info, left = _settings_info, is_in_old\n    else:\n        # no settings, just use new format.\n        info, left = _settings_info, is_in_old\n\n    if prefix:\n        # always use new format if prefix is used.\n        info, left = _settings_info, set()\n\n    # only raise error for keys that the user didn't provide two keys\n    # for (e.g., both ``result_expires`` and ``CELERY_TASK_RESULT_EXPIRES``).\n    really_left = {key for key in left if info.convert[key] not in have}\n    if really_left:\n        # user is mixing old/new, or new/old settings, give renaming\n        # suggestions.\n        raise ImproperlyConfigured(info.mix_error.format(renames='\\n'.join(\n            FMT_REPLACE_SETTING.format(replace=key, with_=info.convert[key])\n            for key in sorted(really_left)\n        )))\n\n    preconf = {info.convert.get(k, k): v for k, v in preconf.items()}\n    defaults = dict(deepcopy(info.defaults), **preconf)\n    return Settings(\n        preconf, [conf, defaults],\n        (_old_key_to_new, _new_key_to_old),\n        deprecated_settings=is_in_old,\n        prefix=prefix,\n    )\n\n\nclass AppPickler:\n    \"\"\"Old application pickler/unpickler (< 3.1).\"\"\"\n\n    def __call__(self, cls, *args):","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/celery/celery/blob/3511be41dbeca8f3c207c997ed9496a656b2a610/celery/app/utils.py#L256-L292","documentation":"Raised in celery/app/utils.py:274 as ImproperlyConfigured when the user's settings simultaneously contain both new-style (lowercase, e.g. `task_serializer`) and old-style (UPPERCASE prefixed, e.g. `CELERY_TASK_SERIALIZER`) keys without a clean rename. Celery's Settings loader detects the mix, picks the majority namespace, and emits a rename suggestion list (`{renames}`). The message lists exactly which keys to rename. The guard prevents ambiguous/partial config where two keys collide.","triggerScenarios":"A settings module that defines both `task_default_queue = 'q'` and `CELERY_DEFAULT_QUEUE = 'q2'`; copying config snippets from different Celery version docs; partial migration off the legacy uppercase format.","commonSituations":"Upgrading from Celery 3.x to 4+ (the big settings rename); mixing project-level new keys with a third-party package that still ships old keys; environment variables injecting old UPPERCASE names alongside new code.","solutions":["Read the `{renames}` list in the error message and rename every listed key to the suggested new name.","Search the config (and env) for the exact old keys reported and remove/replace them.","Use the `configuration_url`/new-format docs for your Celery version to verify all keys are lowercase new-style."],"exampleFix":"// before\nCELERY_TASK_SERIALIZER = 'json'\ntask_result_expires = 3600\n// after\ntask_serializer = 'json'\ntask_result_expires = 3600","handlingStrategy":"validation","validationCode":"OLD_PREFIX = 'CELERY_'\ndef check_settings(settings_dict):\n    mixed = [k for k in settings_dict if k.startswith(OLD_PREFIX)]\n    if mixed:\n        raise SystemExit(f'Remove/rename legacy settings: {mixed}')","typeGuard":"def is_new_style_key(key: str) -> bool:\n    return not key.startswith('CELERY_')","tryCatchPattern":"from celery.exceptions import ImproperlyConfigured\ntry:\n    app = Celery('proj', settings_source=...)\nexcept ImproperlyConfigured as e:\n    # parse rename suggestions from the message and fix config\n    ...","preventionTips":["Use only new-style lowercase keys (task_*, result_*, worker_*).","Audit config during upgrades from Celery 3.x.","Avoid copy-pasting settings from different Celery version docs."],"tags":["config","settings","upgrade","migration","improperly-configured"],"backgroundTag":null,"analyzedSha":"3511be41dbeca8f3c207c997ed9496a656b2a610","analyzedAt":"2026-08-09T16:31:06.077Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}