Skip to content

CASSANDRA-21548: cqlsh prompt does not reset to default after dropping the current keyspace - #4994

Closed
arvindKandpal-ksolves wants to merge 2 commits into
apache:trunkfrom
arvindKandpal-ksolves:CASSANDRA-21548
Closed

CASSANDRA-21548: cqlsh prompt does not reset to default after dropping the current keyspace#4994
arvindKandpal-ksolves wants to merge 2 commits into
apache:trunkfrom
arvindKandpal-ksolves:CASSANDRA-21548

Conversation

@arvindKandpal-ksolves

Copy link
Copy Markdown
Contributor

Summary

This PR fixes an issue where the cqlsh shell prompt remains stuck displaying a keyspace name even after that keyspace has been successfully dropped.

Problem

When a user is currently inside a keyspace in cqlsh (e.g., cqlsh:test_ks>) and executes DROP KEYSPACE test_ks;, the server deletes the keyspace, but the client-side cqlsh prompt does not reset to the default cqlsh> prompt. Executing subsequent queries inside the dropped keyspace context throws a Keyspace does not exist error.

Solution

  • Updated perform_simple_statement in pylib/cqlshlib/cqlshmain.py to check if an executed statement is a DROP KEYSPACE statement.
  • If the dropped keyspace matches self.current_keyspace, self.current_keyspace is reset to None, which automatically updates the shell prompt back to cqlsh>.
  • Included safe string manipulation and .lower() normalization to handle edge cases like quoted keyspace names ("Test_KS") and IF EXISTS clauses.

Testing

  • Added automated unit tests in pylib/cqlshlib/test/test_cqlsh_output.py covering:
    1. Standard keyspace drop resetting the prompt.
    2. Dropping a non-active keyspace without altering the current prompt.
    3. Case-sensitive quoted keyspace names and DROP KEYSPACE IF EXISTS syntax.
  • Verified test execution using pytest (python3 -m pytest pylib/cqlshlib/test/test_cqlsh_output.py -k "test_drop_keyspace_prompt_behavior").

patch by Arvind Kandpal; reviewed by TBA for CASSANDRA-21548

Comment thread pylib/cqlshlib/cqlshmain.py
@smiklosovic smiklosovic closed this Aug 7, 2026
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.

3 participants