{"id":"936653dd7638edde","repo":"celery/celery","slug":"missing-project-specify-gcs-project-to-use-gcs-bac","errorCode":null,"errorMessage":"Missing project:specify gcs_project to use gcs backend","messagePattern":"Missing project:specify gcs_project to use gcs backend","errorType":"exception","errorClass":"ImproperlyConfigured","httpStatus":null,"severity":"error","filePath":"celery/backends/gcs.py","lineNumber":69,"sourceCode":"        super().__init__(**kwargs)\n        self._client_lock = RLock()\n        self._pid = getpid()\n        self._retry_policy = DEFAULT_RETRY\n        self._client = None\n\n        conf = self.app.conf\n        if self.url:\n            url_params = self._params_from_url()\n            conf.update(**dictfilter(url_params))\n\n        self.bucket_name = conf.get('gcs_bucket')\n        if not self.bucket_name:\n            raise ImproperlyConfigured(\n                'Missing bucket name: specify gcs_bucket to use gcs backend'\n            )\n        self.project = conf.get('gcs_project')\n        if not self.project:\n            raise ImproperlyConfigured(\n                'Missing project:specify gcs_project to use gcs backend'\n            )\n        self.base_path = conf.get('gcs_base_path', '').strip('/')\n        self._threadpool_maxsize = int(conf.get('gcs_threadpool_maxsize', 10))\n        self.ttl = float(conf.get('gcs_ttl') or 0)\n        if self.ttl < 0:\n            raise ImproperlyConfigured(\n                f'Invalid ttl: {self.ttl} must be greater than or equal to 0'\n            )\n        elif self.ttl:\n            if not self._is_bucket_lifecycle_rule_exists():\n                raise ImproperlyConfigured(\n                    f'Missing lifecycle rule to use gcs backend with ttl on '\n                    f'bucket: {self.bucket_name}'\n                )\n\n    def get(self, key):\n        key = bytes_to_str(key)","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/celery/celery/blob/571efe81202341310b6257304980ba7898ab0f60/celery/backends/gcs.py#L51-L87","documentation":"GCSBackendBase.__init__ reads conf['gcs_project'] (the GCP project id that owns the bucket/client) and requires it; if absent/empty it raises ImproperlyConfigured. Unlike the bucket, the project is NOT inferred from the gcs:// URL, so it must be set in conf explicitly.","triggerScenarios":"Configuring result_backend='gcs://bucket/path' without setting app.conf.gcs_project. The check is `if not self.project` at gcs.py:68.","commonSituations":"Assuming Application Default Credentials also supply the project (they may, but this backend still requires gcs_project); env var GOOGLE_CLOUD_PROJECT not exported; copy-paste config missing the project line; a multi-project account where the default differs from the target.","solutions":["Set app.conf.gcs_project = 'my-gcp-project' explicitly.","Export the env var that feeds gcs_project in the worker environment.","If using ADC, still set gcs_project to the project owning the bucket; the storage Client requires it.","Verify with `print(app.conf.gcs_project)` before starting workers."],"exampleFix":"# before\nresult_backend = 'gcs://my-bucket/results'\napp.conf.gcs_bucket = 'my-bucket'\n# gcs_project unset -> ImproperlyConfigured\n\n# after\napp.conf.gcs_project = 'my-gcp-project'\napp.conf.gcs_bucket = 'my-bucket'","handlingStrategy":"validation","validationCode":"project = app.conf.get('gcs_project')\nassert project, 'Specify gcs_project (the GCP project owning the bucket/client)'\napp.conf.gcs_project = project","typeGuard":"def has_gcs_project(conf) -> bool:\n    return bool(conf.get('gcs_project'))","tryCatchPattern":"from celery.exceptions import ImproperlyConfigured\n\ntry:\n    GCSBackend(app=app, url=url)\nexcept ImproperlyConfigured as exc:\n    if 'gcs_project' in str(exc):\n        log.error('Set gcs_project to the GCP project id')\n    raise","preventionTips":["Always set gcs_project explicitly even when using Application Default Credentials.","Centralize GCP config (project, bucket) in one typed config object.","Fail fast in config loaders if the project env var is missing."],"tags":["celery","gcs","gcp","google-cloud","configuration","python"],"analyzedSha":"571efe81202341310b6257304980ba7898ab0f60","analyzedAt":"2026-08-04T20:17:20.567Z","schemaVersion":2}