Skip to content

Model state after table_delete() #165

Open
@mikecee

Description

@mikecee

Deleting and then immediately trying to (re)create a table for a particular Model i.e.

    CLS.delete_table()
    CLS.create_table(wait=true)

results in a stacktrace and error that the table doesn't exist(!!):

Traceback (most recent call last):
  File "mre2.py", line 36, in <module>
    JavaScriptTears.create_table(wait=True)
  File "/foo/venv/lib/python2.7/site-packages/pynamodb/models.py", line 720, in create_table
    status = cls._get_connection().describe_table()
  File "/foo/venv/lib/python2.7/site-packages/pynamodb/connection/table.py", line 181, in describe_table
    return self.connection.describe_table(self.table_name)
  File "/foo/venv/lib/python2.7/site-packages/pynamodb/connection/base.py", line 553, in describe_table
    tbl = self.get_meta_table(table_name, refresh=True)
  File "/foo/venv/lib/python2.7/site-packages/pynamodb/connection/base.py", line 405, in get_meta_table
    raise TableDoesNotExist(e.response['Error']['Message'])
pynamodb.exceptions.TableDoesNotExist: Table does not exist: `Requested resource not found: Table: table-one not found` 

Code to reproduce on Python 2.7.12 and PynamoDB 1.5.3 (with an ugly, temporary, non-patch workaround commented out):

#!/usr/bin/env python2.7

from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute, NumberAttribute

class JavaScriptTears(Model):

    class Meta:
        table_name='table-one'
        region     = 'us-west-2'
        read_capacity_units = 1
        write_capacity_units = 1

    framework = UnicodeAttribute(hash_key=True)
    version = NumberAttribute(range_key=True)


if __name__ == '__main__':

    # Make if not present
    if not JavaScriptTears.exists():
        print "1. Creating table"
        JavaScriptTears.create_table(wait=True)
    else:
        print "1. Table already exists"

    # Remove it
    print "2. Deleting table"
    JavaScriptTears.delete_table()

    ## Workaround; Force reconnection. Uncomment below
    # JavaScriptTears._connection = None
    # JavaScriptTears._get_connection()

    print "3. Recreating table"
    JavaScriptTears.create_table(wait=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions