{"record":{"id":"69cf319284043719","repo":"apache/beam","slug":"bucket-gs-bucket-name-is-not-owned-by-project-project-id","errorCode":null,"errorMessage":"Bucket gs://{bucket.name} is not owned by project {project_id}.","messagePattern":"Bucket gs://(.+?) is not owned by project (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/gcsio.py","lineNumber":119,"sourceCode":"\n  if bucket_project_number is None:\n    _LOGGER.warning(\n        'Bucket gs://%s does not have a project number. Skipping ownership validation.',\n        bucket.name)\n    return\n\n  try:\n    project_number = _get_project_number(project_id, credentials=credentials)\n  except Exception as e:\n    _LOGGER.warning(\n        'Failed to resolve project number for project %s: %s. '\n        'Skipping bucket ownership validation.',\n        project_id,\n        e)\n    return\n\n  if bucket_project_number != project_number:\n    raise ValueError(\n        f'Bucket gs://{bucket.name} is not owned by project {project_id}.')\n\n\ndef get_or_create_default_gcs_bucket(options):\n  \"\"\"Create a default GCS bucket for this project.\"\"\"\n  if getattr(options, 'dataflow_kms_key', None):\n    _LOGGER.warning(\n        'Cannot create a default bucket when --dataflow_kms_key is set.')\n    return None\n\n  project = getattr(options, 'project', None)\n  region = getattr(options, 'region', None)\n  if not project or not region:\n    return None\n\n  bucket_name = default_gcs_bucket_name(project, region)\n  gcs = GcsIO(pipeline_options=options)\n  bucket = gcs.get_bucket(bucket_name)","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/gcsio.py#L101-L137","documentation":"_validate_bucket_project raises ValueError when a GCS bucket is owned by a different project than the Beam pipeline project. During default bucket creation, Beam compares the bucket's project number with the current project number and fails if they differ.","triggerScenarios":"Running get_or_create_default_gcs_bucket when a bucket with the default name already exists but belongs to another project (e.g. after changing the GCP project ID or reusing a bucket name across projects).","commonSituations":"Reusing an old Dataflow staging bucket name in a new project; project ID renamed/recreated so project numbers differ; shared bucket naming conventions across teams.","solutions":["Use a different, project-specific bucket name (set via options like staging/temp location) so a foreign-named bucket isn't reused.","Create a fresh bucket owned by the current project and configure it explicitly.","Verify the bucket's owner project with `gsutil bucket get` or the storage API.","Delete/reclaim the old bucket if it is no longer needed by the other project."],"exampleFix":"// before\npython -m apache_beam... --project new-proj  # reuses old bucket owned by old-proj\n// after\n--temp_location gs://new-proj-dataflow-temp/temp --staging_location gs://new-proj-dataflow-temp/staging","handlingStrategy":"validation","validationCode":"from google.cloud import storage\nclient = storage.Client(project=project_id)\nb = client.get_bucket(bucket_name)\ninfo = client._connection.api_request('GET', f'/b/{b.name}?projection=noAcl')\n# compare info['projectNumber'] with your project's number before relying on the bucket","typeGuard":"def bucket_owned_by(bucket_info, project_number):\n    return bucket_info.get('projectNumber') == project_number","tryCatchPattern":"try:\n    bucket = get_or_create_default_gcs_bucket(options)\nexcept ValueError as e:\n    logging.error('bucket project mismatch: %s', e)\n    # fall back to an explicitly configured bucket","preventionTips":["Configure explicit temp/staging locations per project","Never assume a default bucket name is owned by the current project","Check bucket ownership with gsutil or storage API","Avoid reusing bucket names across projects"],"tags":["gcs","permissions","project","bucket"],"backgroundTag":"permission-denied","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}