A
A
AlmazKayum2021-09-16 14:43:51
Python
AlmazKayum, 2021-09-16 14:43:51

Why did postgres query stop working in Python?

Hello.
I am using connection to Postgresql 11 via psycopg2.

The code worked fine before.

def get_switch(self):
        with self.conn:
            self.cursor.execute('SELECT switch FROM switches WHERE id=7')
            return self.cursor.fetchone()[0]    

def change_switch(self):
        with self.conn:
            switch = self.get_switch()
            self.cursor.execute('UPDATE switches SET switch=%s WHERE id=7', (not switch,))
            self.conn.commit()


now throws an error
in get_switch
with self.conn:
psycopg2.ProgrammingError: the connection cannot be re-entered recursively


As I understand it, he swears that two times with self.conn: is used.
Why did the exact same lines work well before?
And it doesn't work now?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2021-09-16
@o5a

It swears precisely at the fact that another with conn was launched inside one with conn. Check your code.
Judging by the documentation and googling reviews, this error began to be issued from version 2.9, so maybe they just ran it on an older version earlier, so they didn’t meet it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question