cocoindex-io/cocoindex · error
Invalid BigQuery project: {project!r}
Error message
Invalid BigQuery project: {project!r} What it means
_validate_project_id checks that the BigQuery project ID is a string matching _PROJECT_RE. Project IDs differ from other identifiers (they may contain hyphens), but must still be well-formed; an invalid or non-string project raises this ValueError.
Source
Thrown at python/cocoindex/connectors/bigquery/_target.py:248
if base_type in _LEAF_TYPE_MAPPINGS:
return _LEAF_TYPE_MAPPINGS[base_type]
if isinstance(
type_info.variant, (SequenceType, MappingType, RecordType, UnionType, AnyType)
):
return _JSON_MAPPING
return _JSON_MAPPING
def _validate_identifier(name: str, kind: str = "identifier") -> None:
if not isinstance(name, str) or not _IDENTIFIER_RE.match(name):
raise ValueError(f"Invalid BigQuery {kind}: {name!r}")
def _validate_project_id(project: str) -> None:
if not isinstance(project, str) or not _PROJECT_RE.match(project):
raise ValueError(f"Invalid BigQuery project: {project!r}")
def _quote_path(parts: Sequence[str]) -> str:
return f"`{'.'.join(parts)}`"
def _qualified_table_name(project: str | None, dataset: str, table_name: str) -> str:
parts = []
if project is not None:
_validate_project_id(project)
parts.append(project)
_validate_identifier(dataset)
_validate_identifier(table_name)
parts.extend([dataset, table_name])
return _quote_path(parts)
def _qualified_dataset_name(project: str | None, dataset: str) -> str:View on GitHub (pinned to e84aa99b32)
Solutions
- Pass the bare Google Cloud project ID, e.g. 'my-proj-123456', not 'projects/my-proj-123456'.
- Check the env/config source: ensure the variable holding the project is set and non-empty.
- Strip whitespace and any 'projects/' prefix before calling.
- Match the regex your version uses: typically lowercase letters, digits, and hyphens, starting with a letter.
Example fix
// before
project = os.environ.get("GCP_PROJECT") # None if unset
target = table_target(client, f"{project}.ds.tbl", Row, primary_key=["id"])
// after
project = os.environ["GCP_PROJECT"] # fails fast if unset
target = table_target(client, f"{project}.ds.tbl", Row, primary_key=["id"]) Defensive patterns
Strategy: validation
Validate before calling
import re
assert re.fullmatch(r"[a-z][a-z0-9-]{4,28}[a-z0-9]", project or ""), f"invalid GCP project id: {project!r}" Type guard
def valid_project_id(project: object) -> bool:
import re
return isinstance(project, str) and bool(re.fullmatch(r"[a-z][a-z0-9-]{4,28}[a-z0-9]", project)) Try / catch
try:
target = table_target(client, f"{project}.{dataset}.{table}", Row, primary_key=pk)
except ValueError as e:
logger.error("invalid project: %s", e)
raise Prevention
- Read the project from a required env var (os.environ[...]) so unset values fail early.
- Strip 'projects/' prefixes and whitespace before use.
- Keep GCP project IDs lowercase letters, digits, hyphens.
When it happens
Trigger: Calling table_target or the qualified-name helpers with a project ID containing illegal characters (spaces, underscores where disallowed by the regex, empty string) or a non-string value like None or an int.
Common situations: Unset environment variable yielding None or '' for the project; pasting a resource name like 'projects/my-proj' instead of the bare project ID; typo'd project slug.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- Invalid BigQuery {kind}: {name!r}
- expected None{loc}, got {type(value).__name__}
- expected {tp}{loc}, got {type(value).__name__}: {value!r}
- expected tuple{loc}, got {type(value).__name__}
- expected {tp}{loc}, got {type(value).__name__}
AI-assisted analysis of cocoindex-io/cocoindex@e84aa99b32 (2026-09-08).
Data as JSON: /api/errors/0118ac878428e23e.
Report an issue: GitHub.