Skip to content

fix: enforce 255-character identifier length limit for Databricks relations#1391

Merged
sd-db merged 5 commits into
databricks:mainfrom
psaikaushik:fix/1309-relation-max-name-length
Apr 25, 2026
Merged

fix: enforce 255-character identifier length limit for Databricks relations#1391
sd-db merged 5 commits into
databricks:mainfrom
psaikaushik:fix/1309-relation-max-name-length

Conversation

@psaikaushik
Copy link
Copy Markdown
Contributor

Summary

Enforces the 255-character identifier length limit for Databricks relations at relation creation time, preventing a cryptic runtime DatabricksExecutionError when store_failures generates overly-long table names.

Closes #1309

Problem

When store_failures: true is enabled, dbt generates table names by concatenating the test name, model name, and arguments. For deep schema tests with verbose names, this can exceed Databricks' 255-character limit for table names, causing:

[RequestId=...] Invalid input: RPC CreateStagingTable Field
managedcatalog.StagingTableInfo.name: name "accepted_map_keys_stg_product_search_create_sizes__relax__..." too long.
Maximum length is 255 characters.

This error is unhelpful — it doesn't explain what the 255-character limit is, which test/model caused it, or how to fix it.

Fix

Added relation_max_name_length() and __post_init__ validation to DatabricksRelation, following the exact same pattern used by the Postgres adapter:

MAX_CHARACTERS_IN_IDENTIFIER = 255

def relation_max_name_length(self):
    return MAX_CHARACTERS_IN_IDENTIFIER

def __post_init__(self):
    if (
        self.identifier is not None
        and self.type is not None
        and len(self.identifier) > self.relation_max_name_length()
    ):
        raise DbtRuntimeError(
            f"Relation name '{self.identifier}' "
            f"is longer than {self.relation_max_name_length()} characters. ..."
        )

Before:

[RequestId=...] Invalid input: RPC CreateStagingTable ... name "accepted_map_keys_stg_..." too long.

After:

Relation name 'accepted_map_keys_stg_product_search_create_sizes__...'
is longer than 255 characters. Databricks has a maximum identifier
length of 255 characters. If this is a store_failures table, consider
using a shorter test name or setting a custom alias.

Checklist

  • Follows the same pattern as the Postgres adapter
  • Catches the error at relation creation time, not at SQL execution
  • Error message includes actionable guidance

@sd-db
Copy link
Copy Markdown
Collaborator

sd-db commented Apr 21, 2026

HI @psaikaushik can you select Allow edits from maintainers or do a rebase from main. The tests are failing because the branch is in an inconsistent state w.r.t CI and can 't review without it.

Copy link
Copy Markdown
Collaborator

@sd-db sd-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the issues raised, let us also add an entry in CHANGELOG.md on the fix. Thanks again for the PR.

Comment thread dbt/adapters/databricks/relation.py Outdated
Comment thread dbt/adapters/databricks/relation.py Outdated
Comment thread dbt/adapters/databricks/relation.py Outdated
@psaikaushik
Copy link
Copy Markdown
Contributor Author

HI @psaikaushik can you select Allow edits from maintainers or do a rebase from main. The tests are failing because the branch is in an inconsistent state w.r.t CI and can 't review without it.

Just allowed edit for maintainers and also rebased on the main. Thanks @sd-db

…ations

Add relation_max_name_length() returning 255 and a __post_init__
validation to DatabricksRelation, following the same pattern used by
the Postgres adapter. This catches overly-long table names (commonly
generated by store_failures for tests with verbose names) at relation
creation time with a clear error message instead of a cryptic runtime
DatabricksExecutionError from the SQL engine.

Closes databricks#1309
@psaikaushik psaikaushik force-pushed the fix/1309-relation-max-name-length branch from 8494a15 to 6688bce Compare April 21, 2026 21:57
@psaikaushik
Copy link
Copy Markdown
Contributor Author

@sd-db : Please take a look at the PR now. Addressed all the comments. Thanks!

@psaikaushik psaikaushik requested a review from sd-db April 21, 2026 21:58
@psaikaushik psaikaushik force-pushed the fix/1309-relation-max-name-length branch from 0c3add9 to 2e759c2 Compare April 21, 2026 22:14
…ength validation (databricks#1309)

Address review feedback:
- Remove verbose comment block from MAX_CHARACTERS_IN_IDENTIFIER constant
- Remove redundant inline comments from __post_init__ (implied by the code)
- Simplify the error message (no repetition of the limit value)
- Add TestIdentifierLengthValidation unit tests covering valid length,
  too-long raises DbtRuntimeError, no-type skips check, None identifier
- Add CHANGELOG entry under 1.11.7

https://claude.ai/code/session_017ZAXMwLSnqz4FqvTt5H7D1
@psaikaushik psaikaushik force-pushed the fix/1309-relation-max-name-length branch from 2e759c2 to a8b866b Compare April 21, 2026 22:17
@sd-db sd-db self-assigned this Apr 22, 2026
Comment thread dbt/adapters/databricks/relation.py Outdated
Comment thread tests/unit/test_relation.py Outdated
Comment thread dbt/adapters/databricks/relation.py Outdated
Comment thread CHANGELOG.md Outdated
Comment thread dbt/adapters/databricks/relation.py Outdated
- Add @classmethod decorator and -> int return type to relation_max_name_length()
- Broaden error message to not mention store_failures specifically; the
  validator fires on any oversized identifier (models, seeds, snapshots, etc.)
- Remove test_relation_max_name_length test (failing and not required per review)
- Move CHANGELOG entry from 1.11.7 to new 1.11.8 section

https://claude.ai/code/session_017ZAXMwLSnqz4FqvTt5H7D1
@psaikaushik psaikaushik force-pushed the fix/1309-relation-max-name-length branch from 87ebdcf to 75a59a3 Compare April 22, 2026 16:57
@psaikaushik
Copy link
Copy Markdown
Contributor Author

@sd-db : Addressed all the comments. Please take a look. thanks!

@psaikaushik psaikaushik requested a review from sd-db April 22, 2026 17:06
psaikaushik and others added 2 commits April 22, 2026 17:08
Error message called relation_max_name_length() three times and stated
the limit redundantly. Align with reviewer's exact suggested wording:
"Databricks has a maximum identifier length of N characters. Use a
shorter name or configure a custom alias."

Update test match pattern accordingly.

https://claude.ai/code/session_017ZAXMwLSnqz4FqvTt5H7D1
@sd-db
Copy link
Copy Markdown
Collaborator

sd-db commented Apr 25, 2026

/integration-test

@github-actions
Copy link
Copy Markdown

Integration tests dispatched for PR #1391 by @sd-db. Track progress in the Actions tab.

@github-actions
Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  dbt/adapters/databricks
  relation.py
Project Total  

This report was generated by python-coverage-comment-action

@github-actions
Copy link
Copy Markdown

Integration results for PR #1391 — UC cluster ✅ success · SQL warehouse ✅ success · All-purpose cluster ✅ success

Run details.

Copy link
Copy Markdown
Collaborator

@sd-db sd-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, thx for the fix!

@sd-db sd-db merged commit d66311a into databricks:main Apr 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] DatabricksExecutionError when store_failures creates table names > 255 characters

2 participants