calling sync_table results in KeyError

Description

Calling management.sync_table method results in KeyError when trying to sync models with a keyspace in AWS Keyspaces.

COMMAND:
% python manage.py sync_cassandra

Stack Trace:
Creating keyspace rcTest [CONNECTION cassandra] ..
Syncing auth.models.Token
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Users/om/Desktop/rc/rc/lib/python3.7/site-packages/django/core/management/_init_.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/om/Desktop/rc/rc/lib/python3.7/site-packages/django/core/management/_init_.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/om/Desktop/rc/rc/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/om/Desktop/rc/rc/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/Users/om/Desktop/rc/rc/lib/python3.7/site-packages/django_cassandra_engine/management/commands/sync_cassandra.py", line 107, in handle
self.sync(alias)
File "/Users/om/Desktop/rc/rc/lib/python3.7/site-packages/django_cassandra_engine/management/commands/sync_cassandra.py", line 93, in sync
connections=[alias])
File "/Users/om/Desktop/rc/rc/lib/python3.7/site-packages/cassandra/cqlengine/management.py", line 190, in sync_table
_sync_table(m, connection=connection)
File "/Users/om/Desktop/rc/rc/lib/python3.7/site-packages/cassandra/cqlengine/management.py", line 274, in _sync_table
table = cluster.metadata.keyspaces[ks_name].tables[raw_cf_name]
KeyError: 'user_details'
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "cassandra/cluster.py", line 221, in cassandra.cluster._shutdown_clusters
File "cassandra/cluster.py", line 1759, in cassandra.cluster.Cluster.shutdown
File "cassandra/cluster.py", line 3147, in cassandra.cluster.Session.shutdown
File "cassandra/pool.py", line 493, in cassandra.pool.HostConnection.shutdown
File "/Users/om/Desktop/rc/rc/lib/python3.7/site-packages/cassandra/io/libevreactor.py", line 296, in close
ConnectionShutdown("Connection to %s was closed" % self.endpoint))
File "cassandra/connection.py", line 207, in cassandra.connection.DefaultEndPoint._str_
TypeError: %d format: a number is required, not str

I had to run `python manage.py sync_cassandra` N number of times to sync all the models I have in my python project, where N is the number of models in the project.

Thanks in advance!

Environment

Python 3.7.6
Clang 11.0.0 (clang-1100.0.33.16) on darwin
django-cassandra-engine==1.6.1
cassandra-driver=3.24

Pull Requests

None

Activity

Show:
Om Prakash
July 17, 2020, 8:20 PM

Seems like Amazon Keyspaces creates Keyspaces and Tables asynchronously. I think the datastax driver does table creation and verifying table synchronously and that’s where the problem is. https://docs.aws.amazon.com/keyspaces/latest/devguide/functional-differences.html#functional-differences.table-keyspace-management

Alan Boudreault
July 23, 2020, 11:53 AM

Hi ,

Indeed, sync_table requires that the keyspace exists. You might want to create a ticket for the django-cassandra-engine project, which is not part of our object mapper. They could simply wait until the keyspace is in the metadata before executing sync_table.

Invalid

Assignee

Unassigned

Reporter

Om Prakash

Fix versions

None

Labels

Reproduced in

3.24

PM Priority

None

External issue ID

None

Doc Impact

None

Reviewer

None

Size

S

Pull Request

None

Components

Affects versions

Priority

Major
Configure