- edited description
Oracle zxJDBC fails with AttributeError in object OracleCompiler_zxjdbc
I understand that Oracle zxJDBC is not currently supported but, in my case, it seems that a simple fix has brought it back to life.
Currently, working with Oracle zxJDBC with Jython 2.7.1b2 fails:
Traceback (most recent call last):
File "/Users/carlos/projects/pydev/smaf-flask/main.py", line 70, in <module>
db.session.commit()
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/orm/scoping.py", line 150, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/orm/session.py", line 813, in commit
self.transaction.commit()
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/orm/session.py", line 392, in commit
self._prepare_impl()
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/orm/session.py", line 372, in _prepare_impl
self.session.flush()
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/orm/session.py", line 2027, in flush
self._flush(objects)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/orm/session.py", line 2145, in _flush
transaction.rollback(_capture_exception=True)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/orm/session.py", line 2109, in _flush
flush_context.execute()
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/orm/unitofwork.py", line 373, in execute
rec.execute(self)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/orm/unitofwork.py", line 529, in execute
persistence.save_obj(self.mapper,
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/orm/persistence.py", line 172, in save_obj
_emit_insert_statements(base_mapper, uowtransaction,
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/orm/persistence.py", line 799, in _emit_insert_statements
result = cached_connections[connection].\
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/engine/base.py", line 914, in execute
return meth(self, multiparams, params)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/engine/base.py", line 996, in _execute_clauseelement
compiled_sql = elem.compile(
File "<string>", line 1, in <lambda>
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/sql/elements.py", line 494, in compile
return self._compiler(dialect, bind=bind, **kw)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/sql/elements.py", line 500, in _compiler
return dialect.statement_compiler(dialect, self, **kw)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/dialects/oracle/base.py", line 581, in __init__
super(OracleCompiler, self).__init__(*args, **kwargs)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/sql/compiler.py", line 392, in __init__
Compiled.__init__(self, dialect, statement, **kwargs)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/sql/compiler.py", line 190, in __init__
self.string = self.process(self.statement, **compile_kwargs)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/sql/compiler.py", line 213, in process
return obj._compiler_dispatch(self, **kwargs)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/sql/visitors.py", line 81, in _compiler_dispatch
return meth(self, **kw)
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/sql/compiler.py", line 1875, in visit_insert
returning_clause = self.returning_clause(
File "/opt/python/jyflask/Lib/site-packages/sqlalchemy/dialects/oracle/zxjdbc.py", line 74, in returning_clause
columns = [self.process(c, within_columns_clause=False,
AttributeError: 'OracleCompiler_zxjdbc' object has no attribute 'result_map'
It seems that the problem stems from within the zxjdbc.py
file in oracle/dialects
folder.
Changing line:
# within_columns_clause=False so that labels (foo AS bar) don't render
columns = [self.process(c, within_columns_clause=False,
result_map=self.result_map)
for c in self.returning_cols]
to:
# within_columns_clause=False so that labels (foo AS bar) don't render
columns = [self.process(c, within_columns_clause=False,
result_map=self._create_result_map())
for c in self.returning_cols]
seems to fix the issue. I've searched BitBucket for an existing ticket but to no avail. Please, can you let me know that this is the correct approach to fix this file? Thanks!
I should also note that I used Oracle 11.2.0.4.0 ojdbc6.jar
Comments (13)
-
Account Deleted reporter -
Account Deleted reporter - edited description
-
repo owner last I tried Jython, SQLAlchemy wouldn't run at all on it.
the patch is probably not correct as the "result_map" keyword argument is not used by the 1.0 version of compiler. Since this is "within_columns_clause=False" I don't think any result map parameters are needed here.
-
Account Deleted reporter For the most part, using Jython 2.7.1b2 with OracleHandler.java included (compiled against 11.0.2.4.0) seems to work... perfectly fine. :)
If the
result_map
keyword is not used, is it safe to remove? Thanks for your feedback.EDIT: Though, I will have to say I haven't done any nasty joins or m2m queries. For the most part, starting up my Flask application works along my simple test cases (CREATE/INSERT/DELETE/SELECT).
-
Account Deleted reporter If it helps, I've created a rather crude project that showcases working zxJDBC functionality with SQLAlchemy:
https://github.com/furritos/flaskito
It basically is flask/flask-sqlalchemy with Jython 2.7.1b2 using zxJDBC dialect for Oracle (ojdbc6.jar not included). You basically edit
flaskito.py
(updating Oracle URI), run thebin/pack
file, deploy it against Tomcat and watch the log files. -
Account Deleted reporter - attached oracle_poc.txt
Attaching log file output from Tomcat - shows raw SQL statements working in sample application.
-
repo owner yes I'd just remove the "result_map" parameter there entirely.
-
repo owner - changed milestone to 1.x.xx
whether or not this works on your end is part of what I'd merge here, otherwise I need to just put this out for if/when we have resources to do Jython work again.
-
Account Deleted reporter I'm looking to branch and submit a PR by the end of this week. As a side note, removing "result_map" worked. Thanks!
-
Account Deleted reporter Created branch and PR.
-
repo owner - changed status to resolved
→ <<cset 9149fd062b8b>>
-
repo owner (cherry picked from commit 9149fd062b8b5f4d84902b4581288ab991fd25ce)
→ <<cset 17521452e09d>>
-
repo owner - changed milestone to 1.0.xx
thanks for the PR!
- Log in to comment