sync_table : AttributeError: 'NoneType' object has no attribute 'replace'

665 views
Skip to first unread message

Srikanth Bemineni

unread,
Dec 27, 2015, 5:50:16 PM12/27/15
to DataStax Python Driver for Apache Cassandra User Mailing List
Hi,

I am getting the below error while using the sync_table in cqlengine. There was a similar issue seen by an other user. The resolution was to connect to the database first.I did connect to the database , and have verified the connection.With the same session object, I was even able to execute a query. I am trying to come up with a module similar to rails migration for my project.

"CQLENG_ALLOW_SCHEMA_MANAGEMENT" is the warning causing this error. I was not able to find enough documentation regarding this warning.

    session = connection.get_session()
    cluster = session.cluster
    metadata=cluster.metadata

    for host in metadata.all_hosts():
        log.info("Datacenter = %s Host = %s , Rack = %s",host.datacenter, host.address,host.rack)

class MigrationTable(Model):
    uid                 = columns.UUID(primary_key=True,default=uuid.uuid4)
    migrationversion     = columns.Text(required=True)
    updateddate            = columns.DateTime(required=True)

sync_table(MigrationTable)



2015-12-27 16:38:24,084 INFO  [myproject.scripts.initializecdb:79][MainThread] Datacenter = datacenter1 Host = 127.0.0.1 , Rack = rack1
2015-12-27 16:38:24,085 INFO  [myproject.scripts.initializecdb:81][MainThread] Connected to database with user myproject and myproject
2015-12-27 16:38:24,085 INFO  [myproject.scripts.initializecdb:99][MainThread] Datacenter = datacenter1 Host = 127.0.0.1 , Rack = rack1
MigrationTable <uid=b6cc3e03-7804-4299-84c8-6869f03c87df>
201506134065
2015-12-27 22:38:24.086128+00:00
2015-12-27 16:38:24,086 INFO  [myproject.scripts.initializecdb:115][MainThread] Creating migration table in the myproject
<class 'myproject.cmodels.migration.MigrationTable'>
/home/izero/devel/my_project/my_project_env/lib/python3.4/site-packages/cassandra/cqlengine/management.py:419: UserWarning: CQLENG_ALLOW_SCHEMA_MANAGEMENT environment variable is not set. Future versions of this package will require this variable to enable management functions.
  warnings.warn(msg)
Traceback (most recent call last):
  File "/home/izero/devel/my_project/my_project_env/bin/initialize_myproject_cdb", line 9, in <module>
    load_entry_point('myproject==0.0', 'console_scripts', 'initialize_myproject_cdb')()
  File "/home/izero/devel/my_project/myproject/myproject/scripts/initializecdb.py", line 88, in main
    create_schema(settings['mc_app_name'],log)
  File "/home/izero/devel/my_project/myproject/myproject/cmodels/migrations/__init__.py", line 109, in create_schema
    createMigrationTable(keyspace,log)
  File "/home/izero/devel/my_project/myproject/myproject/cmodels/migrations/__init__.py", line 117, in createMigrationTable
    sync_table(MigrationTable)
  File "/home/izero/devel/my_project/my_project_env/lib/python3.4/site-packages/cassandra/cqlengine/management.py", line 135, in sync_table
    cf_name = model.column_family_name()
  File "/home/izero/devel/my_project/my_project_env/lib/python3.4/site-packages/cassandra/cqlengine/models.py", line 483, in column_family_name
    return '{0}.{1}'.format(protect_name(cls._get_keyspace()), cf_name)
  File "cassandra/metadata.py", line 1226, in cassandra.metadata.protect_name (cassandra/metadata.c:27387)
  File "cassandra/metadata.py", line 1260, in cassandra.metadata.maybe_escape_name (cassandra/metadata.c:28214)
  File "cassandra/metadata.py", line 1264, in cassandra.metadata.escape_name (cassandra/metadata.c:28294)
AttributeError: 'NoneType' object has no attribute 'replace'

Srikanth Bemineni

Srikanth Bemineni

unread,
Dec 27, 2015, 6:15:51 PM12/27/15
to DataStax Python Driver for Apache Cassandra User Mailing List

FYI

My connection code

    auth_provider = PlainTextAuthProvider(
            username=settings['mc_cassandra_user'], password=settings['mc_cassandra_pass'])

    connection.setup(hosts, settings['mc_app_name'].lower() , protocol_version=3 , auth_provider=auth_provider)

Srikanth Bemineni

unread,
Dec 28, 2015, 10:56:47 AM12/28/15
to DataStax Python Driver for Apache Cassandra User Mailing List
After digging through some code in connection.setup and metadata.py, I think was able to figure out what was the issue. I started this project recently, totally new to cassandra and its datastax drivers. Going through so much documentation, I was using using both regular cqlengine(module) and the new integrated cassandra python driver integrated cqlengine. In connection.setup, before connecting to the cluster, cqlengine updates the models.DEFAULT_KEYSPACE.

In my case I was using the regular cqlengine connection and my models where created using cassandra.cqlengine.model. cassandra.cqlengine.model default keyspace was not set during the setup.

Srikanth Bemineni


On Sunday, December 27, 2015 at 4:50:16 PM UTC-6, Srikanth Bemineni wrote:

Adam Holmberg

unread,
Jan 5, 2016, 10:07:56 AM1/5/16
to python-dr...@lists.datastax.com
Thanks for following up. The python driver should warn if it sees legacy cqlengine installed when it is being installed. It could be easy to miss though. There is nothing preventing side-by-side use, but it's not intended.

Regards,
Adam Holmberg

--
You received this message because you are subscribed to the Google Groups "DataStax Python Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-driver-u...@lists.datastax.com.

Reply all
Reply to author
Forward
0 new messages