Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions apps/blogs/migrations/0004_auto_20260222_0834.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.2.11 on 2026-02-22 08:34

from django.db import migrations


def rewrite_blog_urls(apps, schema_editor):
BlogEntry = apps.get_model("blogs", "BlogEntry")
entries_to_update = []
for entry in BlogEntry.objects.filter(url__contains="pythoninsider.blogspot.com"):
entry.url = entry.url.replace("pythoninsider.blogspot.com", "blog.python.org")
entries_to_update.append(entry)
if entries_to_update:
BlogEntry.objects.bulk_update(entries_to_update, ['url'])


class Migration(migrations.Migration):

dependencies = [
('blogs', '0003_alter_relatedblog_creator_and_more'),
Comment on lines +13 to +19
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration file doesn’t follow the repo’s enforced ruff-format style (notably quote-style = "double" in pyproject.toml; e.g., ['url'] and ('blogs', ...) will be reformatted). Please run ruff format / pre-commit so the lint workflow doesn’t fail on formatting-only differences.

Suggested change
BlogEntry.objects.bulk_update(entries_to_update, ['url'])
class Migration(migrations.Migration):
dependencies = [
('blogs', '0003_alter_relatedblog_creator_and_more'),
BlogEntry.objects.bulk_update(entries_to_update, ["url"])
class Migration(migrations.Migration):
dependencies = [
("blogs", "0003_alter_relatedblog_creator_and_more"),

Copilot uses AI. Check for mistakes.
]

operations = [
migrations.RunPython(rewrite_blog_urls, migrations.RunPython.noop),
]
7 changes: 6 additions & 1 deletion apps/blogs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ def get_all_entries(feed_url):
for e in d["entries"]:
published = datetime.datetime(*e["published_parsed"][:7], tzinfo=datetime.UTC)

# Rewrite Blogger domains to canonical python.org domain (Issue #2685)
url = e["link"].replace(
"//pythoninsider.blogspot.com",
"//blog.python.org"
)
Comment on lines +21 to +25
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL rewriting uses a plain string replacement on the full URL. This can accidentally rewrite URLs whose hostname only starts with pythoninsider.blogspot.com (e.g., pythoninsider.blogspot.com.evil.com) and doesn’t explicitly validate the netloc. Consider parsing the URL and rewriting the hostname only when netloc exactly matches pythoninsider.blogspot.com (then reconstruct the URL), which is both safer and more robust.

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +25
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new multiline replace() call formatting doesn’t match the repo’s enforced ruff-format output (see pyproject.toml [tool.ruff.format] quote-style = "double"). Running ruff format / pre-commit should reformat this block (likely collapsing it to a single line and adjusting commas/parentheses); please apply the formatter so CI lint passes.

Suggested change
url = e["link"].replace(
"//pythoninsider.blogspot.com",
"//blog.python.org"
)
url = e["link"].replace("//pythoninsider.blogspot.com", "//blog.python.org")

Copilot uses AI. Check for mistakes.
entry = {
"title": e["title"],
"summary": e.get("summary", ""),
"pub_date": published,
"url": e["link"],
"url": url,
}

entries.append(entry)
Expand Down
24 changes: 24 additions & 0 deletions apps/blogs/tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import unittest
from unittest.mock import patch

from apps.blogs.parser import get_all_entries
from apps.blogs.tests.utils import get_test_rss_path
Expand All @@ -24,3 +25,26 @@ def test_entries(self):
self.entries[0]["url"],
"http://feedproxy.google.com/~r/PythonInsider/~3/tGNCqyOiun4/introducing-electronic-contributor.html",
)

@patch("apps.blogs.parser.feedparser.parse")
def test_rewrites_blogspot_url(self, mock_parse):
mock_parse.return_value = {
"entries": [
{
"title": "Test Title HTTPS",
"summary": "Summary",
"published_parsed": (2024, 1, 15, 12, 0, 0, 0, 0, 0),
"link": "https://pythoninsider.blogspot.com/2024/01/test.html",
},
{
"title": "Test Title HTTP",
"summary": "Summary",
"published_parsed": (2024, 1, 15, 12, 0, 0, 0, 0, 0),
"link": "http://pythoninsider.blogspot.com/2024/01/test2.html",
}
]
Comment on lines +44 to +45
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new mocked return value literal is not ruff-formated (e.g., missing trailing commas in a multiline list/dict). Since CI runs pre-commit with ruff-format, please run ruff format (or pre-commit) to avoid formatting-only lint failures.

Suggested change
}
]
},
],

Copilot uses AI. Check for mistakes.
}
entries = get_all_entries("http://fake.url")
self.assertEqual(len(entries), 2)
self.assertEqual(entries[0]["url"], "https://blog.python.org/2024/01/test.html")
self.assertEqual(entries[1]["url"], "http://blog.python.org/2024/01/test2.html")
Loading