Triggers broken after move from PyPy to CPython

10 views
Skip to first unread message

Ankit Soni

unread,
Aug 13, 2020, 3:43:46 PM8/13/20
to sqlalchemy
We are attempting to move to CPython from PyPy (both version 2.7), but I'm seeing some baffling errors in the process. 
 
We are using SQLAlchemy 1.3.11, Flask-SqlAlchemy 2.4.11, psyocpg2cffi, postgres in our application. 


There is an "A" model with a post create hook like:

event.listen(A.__table__, "after_create", create_default_A)

def create_default_A():
  a = A(....)
  db.session.add(a)
  db.session.flush()
  b = B(...., a_id = a.id)
  db.session.add(b)
  db.session.commit()

This works fine with PyPy, however, with CPython, the commit fails with an error from postgres saying the "B" table does not exist.

As far as I understand there should be no difference. What is going wrong here?
 

Mike Bayer

unread,
Aug 13, 2020, 3:54:47 PM8/13/20
to noreply-spamdigest via sqlalchemy
Would be very strange but the main difference between pypy and cpython is the garbage collection in cPython is usually immediate for an object withotu reference cycles whereas in Pypy it's not immediate.   If this example were in a test suite where the "B" table were created in a transient way such that it goes away once some resource like a connection or similar is garbage collected, the behavior could differ in Pypy vs. cPython.

it would be pretty tough to make the above happen however especially that PostgreSQL creates tables in isolated transactions.

so, like all such issues, you need to turn on SQL logging /echoing and watch as the "B" is created, ensure it exists, and then detect if "B" is somehow going away or being dropped ahead of time.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages