No updates in the database while debugging
Hello to everyone!
I faced the following problem while debugging in PyCharm Professional Edition. During stepping over, I was expecting to see the line-by-line code execution with writing data to the database when code does so. But during the code execution, I didn't see new writings in the DB. Reloading the database didn't show the new records either. But when I print requests to the DB for this data, they are shown in the console but not displayed in the PyCharm. Should the database be updated during the code execution while debugging? I use PostgreSQL 12.8 as DB.
Best regards,
Dmytro Skoryi
Please sign in to leave a comment.
how do you perform debug? is it Python code?
Yes, it is a Python code. At first, I create a debug configuration to run a custom command with positional argument. After that, I perform line by line code execution from a certain breakpoint. Then, when I use Django ORM to save an object in a code, the actual record is not displayed in the connected database, even after refresh. The record actually appears later in the DB somewhere in the middleware, although it should appear after calling .save() method on an object.
and how do you check for new records? Is it also a request from your Python code using same connection?
or do you use Database Tools and SQL plugin to connect to database and view table data using IDE capabilities?
I use database tools and SQL plugin to view table using IDE.
Could you please create Python script to get data directly from database and check if behavior is the same?
I created a script that used Django ORM to access the database for newly written data. This script showed that data were in the table, however IDE did not display them in database plugin. Reloading the table in the IDE did not show them.
Hello
You should be able to see new records from IDE while debugging in case .save() method executes update immediately and commits transaction (or uses auto commit)
1. Do you use transactions explicitly in script that you debug?
2. Do you see new records in IDE when you press Refresh in a table after debug is finished?