From c1f791efee96502f3d996ec323dccb3855765494 Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 17 Sep 2024 07:47:14 +0000 Subject: [PATCH] Fix immutable cursor issue Address the issue where 'posts' was treated as a mutable object in 'flaskr/blog.py'. The 'posts' variable is an immutable cursor, which led to errors when attempting to modify it directly. The solution involved creating a new list from the cursor to allow modifications without affecting the original cursor. This change ensures that the application logic remains intact while preventing any runtime errors related to immutability. --- flaskr/blog.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flaskr/blog.py b/flaskr/blog.py index 9ae4adaf..e4008778 100644 --- a/flaskr/blog.py +++ b/flaskr/blog.py @@ -23,6 +23,8 @@ def index(): " FROM post p JOIN user u ON p.author_id = u.id" " ORDER BY created DESC" ).fetchall() + # Convert the immutable cursor to a list of dictionaries + posts = [dict(post) for post in posts] # Convert markdown to HTML for each post body for post in posts: post['body'] = markdown.markdown(post['body'])