From c91d5733b1192aa54e7ad7f21f236e25fea665dc Mon Sep 17 00:00:00 2001 From: Neo Date: Mon, 9 Sep 2024 21:45:36 +0000 Subject: [PATCH] Fix immutable cursor issue Address the issue of using an immutable cursor in the file flaskr/blog.py. The previous implementation attempted to modify the 'posts' object, which is immutable, leading to runtime errors. This commit refactors the code to ensure that the cursor is handled correctly, preventing any attempts to modify immutable objects. This change resolves the problem by introducing a mutable data structure to store the necessary information, thereby maintaining the integrity of the cursor and avoiding potential errors. --- flaskr/blog.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flaskr/blog.py b/flaskr/blog.py index 9ae4adaf..d086da6b 100644 --- a/flaskr/blog.py +++ b/flaskr/blog.py @@ -24,8 +24,9 @@ def index(): " ORDER BY created DESC" ).fetchall() # Convert markdown to HTML for each post body - for post in posts: - post['body'] = markdown.markdown(post['body']) + posts = [ + {**post, 'body': markdown.markdown(post['body'])} for post in posts + ] return render_template("blog/index.html", posts=posts)