Skip to content

fix: namespace_exists/table_exists raise NamespaceNotFoundError/TableNotFoundError#6252

Closed
lilei1128 wants to merge 3 commits intolance-format:mainfrom
lilei1128:fix
Closed

fix: namespace_exists/table_exists raise NamespaceNotFoundError/TableNotFoundError#6252
lilei1128 wants to merge 3 commits intolance-format:mainfrom
lilei1128:fix

Conversation

@lilei1128
Copy link
Copy Markdown

namespace_exists() and table_exists() were raising RuntimeError instead of
the documented NamespaceNotFoundError / TableNotFoundError because the
implementations in dir.rs and manifest.rs used Error::namespace_source(String)
— a plain boxed string — which cannot be downcast to NamespaceError in
infer_error(), triggering the fallback RuntimeError path.

Fix by constructing proper NamespaceError variants:

  • manifest.rs namespace_exists: NamespaceError::NamespaceNotFound
  • manifest.rs table_exists: NamespaceError::TableNotFound
  • dir.rs namespace_exists: NamespaceError::Unsupported (child NS without manifest)
  • dir.rs table_exists: NamespaceError::TableNotFound

Also fix rest_adapter.rs error_to_response to dispatch on NamespaceError
error codes instead of fragile string matching, and rest.rs HTTP helpers to
parse the numeric error code from the response body and reconstruct the
correct NamespaceError variant, so the full REST round-trip also raises the
right Python exception.

Update tests to assert TableNotFoundError / NamespaceNotFoundError specifically.

@github-actions github-actions bot added bug Something isn't working python labels Mar 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

ACTION NEEDED
Lance follows the Conventional Commits specification for release automation.

The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification.

For details on the error please inspect the "PR Title Check" action.

@lilei1128
Copy link
Copy Markdown
Author

close #6240

@lilei1128 lilei1128 changed the title fix:namespace_exists/table_exists raise NamespaceNotFoundError/TableNotFoundError fix: namespace_exists/table_exists raise NamespaceNotFoundError/TableNotFoundError Mar 22, 2026
Copy link
Copy Markdown
Contributor

@wjones127 wjones127 left a comment

Choose a reason for hiding this comment

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

This PR looks good. I have a few non-blocking suggestions, but those are pre-existing issues so I'd be fine addressing them in a different PR.

Comment on lines +2243 to +2246
Err(NamespaceError::NamespaceNotFound {
message: format!("Namespace '{}' not found", object_id),
}
.into())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: This message duplicates what is in the Display implementation for this error:

/// The specified namespace does not exist.
#[snafu(display("Namespace not found: {message}"))]
NamespaceNotFound { message: String },

The error will print as:

Namespace not found: Namespace '{name}' not found

Consider just putting the quoted object id as the message:

Suggested change
Err(NamespaceError::NamespaceNotFound {
message: format!("Namespace '{}' not found", object_id),
}
.into())
Err(NamespaceError::NamespaceNotFound {
message: format!("'{}'", object_id)
}
.into())

Then the message would be like:

Namespace not found: '{name}'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you for your correction.

Comment on lines +1352 to +1355
return Err(NamespaceError::TableNotFound {
message: format!("Table does not exist: {}", table_name),
}
.into());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: similar to namespace error comment, this message duplicates the same text. Consider shortening it to:

Suggested change
return Err(NamespaceError::TableNotFound {
message: format!("Table does not exist: {}", table_name),
}
.into());
return Err(NamespaceError::TableNotFound {
message: format!("'{}'", table_name),
}
.into());

Comment on lines +246 to +247
with pytest.raises(Exception):
with pytest.raises(TableNotFoundError):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

praise: I'm very happy to see us asserting more specific errors here 😄

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks! Happy to help make our error handling clearer 😊

@wjones127 wjones127 self-assigned this Mar 23, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance-namespace-impls/src/dir.rs 71.42% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@wjones127
Copy link
Copy Markdown
Contributor

I've received a request from @hamersaw to merge #6275 in favor of this PR, as it contains these changes plus some more. I'll close this out, but thank you for working on this. It was reviewing this I was able to see the duplicate info in the errors more easily 🙌

@wjones127 wjones127 closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants