stefanor / pypy3-snap

PyPy is a fast, compliant alternative implementation of the Python language
MIT License
0 stars 0 forks source link

SQLite3 issue in snap #2

Closed austinjp closed 4 years ago

austinjp commented 4 years ago

Hi. I ran into an issue using PyPy 7.3.1 on Ubuntu 18 when trying to get Pony ORM working. In summary, installing PyPy using apt works fine, while using PyPy installed with snap produces the issue.

Steps to reproduce:

sudo snap install --classic pypy3
cd /tmp/
mkdir pypy-test
cd pypy-test
virtualenv -p /snap/pypy3/current/bin/pypy3 venv
source venv/bin/activate
pip install pony
python -c 'from pony.orm import Database; db = Database(); db.bind(provider="sqlite",filename=":memory:")'

Produces the following output:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 2, in bind
  File "/tmp/pypy-test/venv/site-packages/pony/utils/utils.py", line 78, in cut_traceback
    reraise(exc_type, exc, full_tb)
  File "/tmp/pypy-test/venv/site-packages/pony/utils/utils.py", line 95, in reraise
    try: raise exc.with_traceback(tb)
  File "/tmp/pypy-test/venv/site-packages/pony/utils/utils.py", line 61, in cut_traceback
    try: return func(*args, **kwargs)
  File "/tmp/pypy-test/venv/site-packages/pony/orm/core.py", line 769, in bind
    self._bind(*args, **kwargs)
  File "/tmp/pypy-test/venv/site-packages/pony/orm/core.py", line 791, in _bind
    self.provider = provider_cls(*args, **kwargs)
  File "/tmp/pypy-test/venv/site-packages/pony/orm/dbproviders/sqlite.py", line 328, in __init__
    DBAPIProvider.__init__(provider, *args, **kwargs)
  File "/tmp/pypy-test/venv/site-packages/pony/orm/dbapiprovider.py", line 130, in __init__
    connection, is_new_connection = provider.connect()
  File "<string>", line 2, in connect
  File "/tmp/pypy-test/venv/site-packages/pony/orm/dbapiprovider.py", line 55, in wrap_dbapi_exceptions
    try: return func(provider, *args, **kwargs)
  File "/tmp/pypy-test/venv/site-packages/pony/orm/dbapiprovider.py", line 230, in connect
    return provider.pool.connect()
  File "/tmp/pypy-test/venv/site-packages/pony/orm/dbapiprovider.py", line 351, in connect
    pool._connect()
  File "/tmp/pypy-test/venv/site-packages/pony/orm/dbproviders/sqlite.py", line 671, in _connect
    con.execute('PRAGMA foreign_keys = true')
  File "/snap/pypy3/current/lib_pypy/_sqlite3.py", line 419, in execute
    return cur.execute(*args)
  File "/snap/pypy3/current/lib_pypy/_sqlite3.py", line 773, in wrapper
    return func(self, *args, **kwargs)
  File "/snap/pypy3/current/lib_pypy/_sqlite3.py", line 934, in execute
    return self.__execute(False, sql, [params])
  File "/snap/pypy3/current/lib_pypy/_sqlite3.py", line 884, in __execute
    if self.__connection._begin_statement and self.__statement._is_dml:
AttributeError: 'Connection' object has no attribute '_begin_statement'

The following works fine:

Clean up...

deactivate
sudo snap uninstall pypy3

...then...

sudo apt install pypy3
virtualenv -p /usr/bin/pypy3 venv-again
source venv-again/bin/activate
pip install pony
python -c 'from pony.orm import Database; db = Database(); db.bind(provider="sqlite",filename=":memory:")'

Finishes silently, no errors.

stefanor commented 4 years ago

Thanks for the clear, and reproduceable bug report.

virtualenv doesn't seem to be working with the snappped pypy3 atm, but venv works:

mkdir pypy-test
cd pypy-test
snap run pypy3 -m venv venv
source venv/bin/activate
pip install pony
python -c 'from pony.orm import Database; db = Database(); db.bind(provider="sqlite",filename=":memory:")'

Appears to be fixed in 7.3.2.

stefanor commented 4 years ago

Ah, now that I think about it, this was a known regression in 7.3.1: https://foss.heptapod.net/pypy/pypy/issues/3210

I carried a patch to fix it in Debian/Ubuntu.