r4fek / django-cassandra-engine

Django Cassandra Engine - the Cassandra backend for Django
BSD 2-Clause "Simplified" License
364 stars 85 forks source link

sync_cassandra command fails after syncing 1 model #165

Open psraghuveer opened 1 year ago

psraghuveer commented 1 year ago

Hi,

I am trying to sync 3 tables with Amazon Keyspace. I have setup everything according to the docs and some information I could find on Stackoverflow answers. But, when I run python manage.py sync_cassandra, it errors out after syncing 1 model, while there are 3 models to be synced. However, I can see that the table is created on Amazon Keyspace. When I run the command again, the other tables get synced - but it is quite random. What might be causing this to error out?

My configuration:

{
        "ENGINE": "django_cassandra_engine",
        "NAME": os.getenv("AWS_KEYSPACE_NAME"),
        "HOST": os.getenv("AWS_KEYSPACE_HOST"),
        "OPTIONS": {
            "replication": {
                "strategy_class": "SimpleStrategy",
                "replication_factor": 1,
            },
            "connection": {
                "retry_connect": True,
                "consistency": ConsistencyLevel.LOCAL_QUORUM,
                "port": 9142,
                "ssl_context": ssl_context,
                "auth_provider": PlainTextAuthProvider(username=os.getenv("AWS_KEYSPACE_USERNAME"), password=os.getenv("AWS_KEYSPACE_PASSWORD")),
            },
        },
    }

The error:

Syncing apps.notifications.models.EmailNotificationLog
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/raghuveer/qoohoo/bagheera/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/raghuveer/qoohoo/bagheera/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/raghuveer/qoohoo/bagheera/venv/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/raghuveer/qoohoo/bagheera/venv/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/Users/raghuveer/qoohoo/bagheera/venv/lib/python3.8/site-packages/django_cassandra_engine/management/commands/sync_cassandra.py", line 101, in handle
    self.sync(alias)
  File "/Users/raghuveer/qoohoo/bagheera/venv/lib/python3.8/site-packages/django_cassandra_engine/management/commands/sync_cassandra.py", line 87, in sync
    management.sync_table(model, keyspaces=[keyspace], connections=[alias])
  File "/Users/raghuveer/qoohoo/bagheera/venv/lib/python3.8/site-packages/cassandra/cqlengine/management.py", line 190, in sync_table
    _sync_table(m, connection=connection)
  File "/Users/raghuveer/qoohoo/bagheera/venv/lib/python3.8/site-packages/cassandra/cqlengine/management.py", line 274, in _sync_table
    table = cluster.metadata.keyspaces[ks_name].tables[raw_cf_name]
KeyError: 'email_notification_log'
westover commented 1 year ago

I noticed with Amazon Keyspaces that there is a lag with model creation that seems to cause it to fail