Skip to content

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

Open
psaikaushik wants to merge 4 commits intodatabricks:mainfrom
psaikaushik:fix/1309-relation-max-name-length
Open

fix: enforce 255-character identifier length limit for Databricks relations#1391
psaikaushik wants to merge 4 commits intodatabricks:mainfrom
psaikaushik:fix/1309-relation-max-name-length

Conversation

@psaikaushik
Copy link
Copy Markdown

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
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
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
f"is longer than {self.relation_max_name_length()} characters. "
f"Databricks has a maximum identifier length of "
f"{self.relation_max_name_length()} characters. "
f"If this is a store_failures table, consider using a shorter "
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We have hardcoded store_failures here but the validator fires on any oversized identifier (models/seeds/snapshots)

Comment thread tests/unit/test_relation.py Outdated


class TestIdentifierLengthValidation:
def test_relation_max_name_length(self):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test is failing, also we should remove this test as this is not required.

Comment thread dbt/adapters/databricks/relation.py Outdated
"Use a shorter test name or configure a custom alias."
)

def relation_max_name_length(self):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

imo best to make this a classmethod

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also add a return type annotation -> int

Comment thread CHANGELOG.md Outdated
- Fix `workflow_job` Python model submission method failing with dictionary attribute error ([#1360](https://github.com/databricks/dbt-databricks/issues/1360))
- Fix `TestWorkflowJob` functional test that was unreachable on all profiles due to incorrect skip list, wrong model fixture, and invalid `max_retries` parameter ([#1360](https://github.com/databricks/dbt-databricks/issues/1360))
- Fix column order mismatch in microbatch and replace_where incremental strategies by using INSERT BY NAME syntax ([#1338](https://github.com/databricks/dbt-databricks/issues/1338))
- Validate relation identifier length at creation time and raise a clear error when it exceeds Databricks' 255-character limit, preventing confusing runtime failures when `store_failures: true` generates long table names ([#1309](https://github.com/databricks/dbt-databricks/issues/1309))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Move this to 1.11.8

Comment thread dbt/adapters/databricks/relation.py Outdated
raise DbtRuntimeError(
f"Relation name '{self.identifier}' is longer than "
f"{self.relation_max_name_length()} characters. "
"Use a shorter test name or configure a custom alias."
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

post_init is valid for all relations and not just test. I think a better comment is probably something like - Databricks has a maximum identifier length of 255 characters. Use a shorter name or configure a custom alias.

- 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
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
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
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