Skip to content

Pycassa "UnboundLocalError: local variable 'eoc' referenced before assignment" appears #174

Closed
eprohoda opened this Issue Oct 2, 2012 · 1 comment

2 participants

@eprohoda
eprohoda commented Oct 2, 2012

The goal of this script to add some new row to existent table in database.
It seems that table has row of composite type.
Script takes last row in the table and copy it with new key.
The problem is when we try to insert new row - UnboundLocalError: local variable 'eoc' referenced before assignment is appears.

Please help to resolve this issue.
Note: I deliberately left all prints and output so we could see consistence of the table.

---------------------Code:-------------------------------------------
def connection_to_cassandra(db_name, table_name):
global table
db = ConnectionPool(db_name, ['172.18.198.30:9171'])
table = pycassa.ColumnFamily(db, table_name)

connection_to_cassandra('Database', 'Table')

def get_all_rows():
print "all rows"
for key, columns in table.get_range():
print key, columns

get_all_rows()
def insert_parameters():
values = list(table.get_range())
max_row = max([int(v[0]) for v in values])
row = max_row
result= table.get(row)
print 'result', result
for key, val in result.items():
val=val
#------------------------------
print 'key', key
print type (key)
print 'key[0]', key[0]
d1 = datetime.datetime(2004, 11, 20, 0, 0)
print d1
row = max_row + 1
table.insert(row, {key:'2'})

insert_parameters()

-------------------------------------------Output:-------------------------------------

1 OrderedDict([((datetime.datetime(2012, 6, 30, 0, 0),), 13), ((datetime.datetime(2012, 7, 1, 0, 0),), 10), ((datetime.datetime(2012, 7, 2, 0, 0),), 12), ((datetime.datetime(2012, 7, 3, 0, 0),), 9), ((datetime.datetime(2012, 7, 6, 0, 0),), 22), ((datetime.datetime(2012, 7, 7, 0, 0),), 13), ((datetime.datetime(2012, 7, 30, 0, 0),), 48)])
2 OrderedDict([((datetime.datetime(2012, 6, 30, 0, 0),), 2), ((datetime.datetime(2012, 7, 1, 0, 0),), 14), ((datetime.datetime(2012, 7, 2, 0, 0),), 4), ((datetime.datetime(2012, 7, 3, 0, 0),), 2), ((datetime.datetime(2012, 7, 28, 0, 0),), 1), ((datetime.datetime(2012, 7, 29, 0, 0),), 1), ((datetime.datetime(2012, 7, 30, 0, 0),), 15)])
6 OrderedDict([((datetime.datetime(2012, 7, 18, 0, 0),), 1)])
5 OrderedDict([((datetime.datetime(2012, 7, 7, 0, 0),), 1), ((datetime.datetime(2012, 7, 8, 0, 0),), 1), ((datetime.datetime(2012, 7, 11, 0, 0),), 1), ((datetime.datetime(2012, 7, 15, 0, 0),), 1), ((datetime.datetime(2012, 7, 28, 0, 0),), 1)])
3 OrderedDict([((datetime.datetime(2012, 7, 1, 0, 0),), 3), ((datetime.datetime(2012, 7, 2, 0, 0),), 3), ((datetime.datetime(2012, 7, 3, 0, 0),), 3), ((datetime.datetime(2012, 7, 4, 0, 0),), 5), ((datetime.datetime(2012, 7, 29, 0, 0),), 4), ((datetime.datetime(2012, 7, 30, 0, 0),), 2)])
4 OrderedDict([((datetime.datetime(2012, 7, 1, 0, 0),), 2), ((datetime.datetime(2012, 7, 2, 0, 0),), 1), ((datetime.datetime(2012, 7, 3, 0, 0),), 1), ((datetime.datetime(2012, 7, 5, 0, 0),), 3), ((datetime.datetime(2012, 7, 28, 0, 0),), 2), ((datetime.datetime(2012, 7, 29, 0, 0),), 3)])
1
2
6
5
3
4
max_row: 6
result OrderedDict([((datetime.datetime(2012, 7, 18, 0, 0),), 1)])
key (datetime.datetime(2012, 7, 18, 0, 0),)

key[0] 2012-07-18 00:00:00
2004-11-20 00:00:00
Traceback (most recent call last):
File "/home/eprohoda/projects/hadoop/hadoop_training/src/my_scripts/6.py", line 66, in
insert_parameters()
File "/home/eprohoda/projects/hadoop/hadoop_training/src/my_scripts/6.py", line 62, in insert_parameters
table.insert(row, {key:'2'})
File "/usr/local/lib/python2.7/dist-packages/pycassa/columnfamily.py", line 973, in insert
mut_list = self._make_mutation_list(columns, timestamp, ttl)
File "/usr/local/lib/python2.7/dist-packages/pycassa/columnfamily.py", line 504, in _make_mutation_list
columns.iteritems())
File "/usr/local/lib/python2.7/dist-packages/pycassa/columnfamily.py", line 503, in
return map(lambda (c, v): Mutation(self._make_cosc(_pack_name(c), _pack_value(v, c), timestamp, ttl)),
File "/usr/local/lib/python2.7/dist-packages/pycassa/columnfamily.py", line 421, in _pack_name
return self._name_packer(value, slice_start)
File "/usr/local/lib/python2.7/dist-packages/pycassa/marshal.py", line 124, in pack_composite
s += ''.join((len_packer(len(packed)), packed, eoc))
UnboundLocalError: local variable 'eoc' referenced before assignment

Process finished with exit code 1

@thobbs
pycassa member
thobbs commented Oct 8, 2012

This should be fixed in master by 7e63cd6

@thobbs thobbs closed this Oct 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.