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.
This commit is contained in:
Neo 2024-09-17 07:47:14 +00:00
parent 1d75c45a1d
commit c1f791efee

View file

@ -23,6 +23,8 @@ def index():
" FROM post p JOIN user u ON p.author_id = u.id" " FROM post p JOIN user u ON p.author_id = u.id"
" ORDER BY created DESC" " ORDER BY created DESC"
).fetchall() ).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 # Convert markdown to HTML for each post body
for post in posts: for post in posts:
post['body'] = markdown.markdown(post['body']) post['body'] = markdown.markdown(post['body'])