[Sqlalchemy-tickets] Issue #4125: AttributeError in StrSQLCompiler (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Bryan B. <iss...@bi...> - 2017-10-30 10:53:06
|
New issue 4125: AttributeError in StrSQLCompiler https://bitbucket.org/zzzeek/sqlalchemy/issues/4125/attributeerror-in-strsqlcompiler Bryan Brown: I've attached an image file (only one is needed to reproduce this error but more like it can be added freely) in the proper folder hierarchy. For reference, ``` #!python uuid ``` is a short string, ``` #!python dim ``` is an integer, and ``` #!python array ``` is also a string (of comma-delimited integers). Their output is shown in line 5 of my Output ("Inserting..."). As the code suggests, you'll need a recent build of Pillow to get the PIL functionality. The problem statement seems to be on line 29/30. # scan.py # ``` #!python import os import hashlib import base64 import MySQLdb import sqlalchemy from PIL import Image from sqlalchemy import create_engine, Table, Column, Integer, Text, MetaData from sqlalchemy.dialects import mysql imdim = 8 hasher = hashlib.md5() def getuuid(array): hasher.update(array.encode("utf-8")) return str(base64.urlsafe_b64encode(hasher.digest()),"utf-8") def scan(imdata): for size in range(4,imdim-1,4): for x in range(imdim*(imdim-1)): temp = [] for y in range(size): start = x+(y*imdim) temp = temp + (imdata[start:start+size]) print(temp) temp = [str(x) for x in temp] tempstr = ','.join(temp) uuid = getuuid(tempstr) print("Inserting",uuid,size,tempstr) insert = test.insert().values(uuid=uuid,dim=size,array=tempstr) con.execute(insert.compile()) eng = create_engine('mysql://[creds and ip redacted]/Test') print("Connected") with eng.connect() as con: con.execute('''DROP TABLE IF EXISTS test''') print("Dropped old test") metadata = MetaData() test = Table('test', metadata, Column('uuid', Text), Column('dim', Integer), Column('array', Text), ) metadata.create_all(eng) print("Made new test") thumbs = os.walk('/home/bryan/cake-'+str(imdim)) count = 0 for dirpath, dirnames, filenames in thumbs: for filename in filenames: im = Image.open(os.path.join(dirpath,filename)) imdata = list(im.getdata()) scan(imdata) ``` # Full Output # ``` #!python bryan@cake:~/scripts$ python3 scan.py Connected Dropped old test Made new test [89, 68, 33, 33, 114, 76, 70, 89, 134, 112, 116, 117, 125, 108, 66, 62] Inserting Nyr46IPx33dO-EGb3CX7dA== 4 89,68,33,33,114,76,70,89,134,112,116,117,125,108,66,62 Traceback (most recent call last): File "/home/bryan/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1116, in _execute_context context = constructor(dialect, self, conn, *args) File "/home/bryan/.local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 621, in _init_compiled for key in self.compiled.positiontup: AttributeError: 'StrSQLCompiler' object has no attribute 'positiontup' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "scan.py", line 53, in <module> scan(imdata) File "scan.py", line 30, in scan con.execute(insert.compile()) File "/home/bryan/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 945, in execute return meth(self, multiparams, params) File "/home/bryan/.local/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 227, in _execute_on_connection return connection._execute_compiled(self, multiparams, params) File "/home/bryan/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1075, in _execute_compiled compiled, parameters File "/home/bryan/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1121, in _execute_context None, None) File "/home/bryan/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception exc_info File "/home/bryan/.local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=cause) File "/home/bryan/.local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 186, in reraise raise value.with_traceback(tb) File "/home/bryan/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1116, in _execute_context context = constructor(dialect, self, conn, *args) File "/home/bryan/.local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 621, in _init_compiled for key in self.compiled.positiontup: sqlalchemy.exc.StatementError: (builtins.AttributeError) 'StrSQLCompiler' object has no attribute 'positiontup' [SQL: 'INSERT INTO test (uuid, dim, "array") VALUES (:uuid, :dim, :array)'] ``` # Version # ``` #!python >>> sqlalchemy.__version__ '1.1.14' ``` ``` #!python root@cake-db ~# mysqladmin version -p Enter password: mysqladmin Ver 8.42 Distrib 5.5.58, for debian-linux-gnu on x86_64 Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Server version 5.5.58-0+deb8u1 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 3 days 2 hours 10 min 23 sec Threads: 1 Questions: 2700 Slow queries: 0 Opens: 314 Flush tables: 2 Open tables: 41 Queries per second avg: 0.010 ``` |