Skip to content

Commit

Permalink
Ignore raw post save signal
Browse files Browse the repository at this point in the history
This is a remnant of #106

One should not query/modify other records in the database as the database might not be in a consistent state yet.
  • Loading branch information
timobrembeck authored and claudep committed Feb 27, 2023
1 parent 47b26f3 commit 5952085
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Unreleased

* Ignore raw `post_save` signal (Timo Ludwig, #106).
* Retry with fallback user agent on forbidden response (Timo Ludwig, #159)
* Also set `redirect_to` on internal redirects (Timo Ludwig, #163)
* Add new fields to `Url` model:
Expand Down
4 changes: 4 additions & 0 deletions linkcheck/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ def instance_pre_save(sender, instance, raw=False, **kwargs):


def instance_post_save(sender, instance, **kwargs):
# Ignore raw imports
if kwargs.get('raw'):
return

def do_instance_post_save(sender, instance, **kwargs):
current_url = instance.get_absolute_url()
previous_url = getattr(instance, '__previous_url', None)
Expand Down
7 changes: 7 additions & 0 deletions linkcheck/tests/sampleapp/fixture.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
[
{
"model": "sampleapp.Page",
"pk": 1,
"fields": {
"book": 1
}
},
{
"model": "sampleapp.Book",
"pk": 1,
Expand Down
8 changes: 7 additions & 1 deletion linkcheck/tests/sampleapp/linklists.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db.models import OuterRef, Subquery

from linkcheck import Linklist
from linkcheck.tests.sampleapp.models import Author, Book, Journal
from linkcheck.tests.sampleapp.models import Author, Book, Journal, Page


class BookLinklist(Linklist):
Expand All @@ -11,6 +11,11 @@ class BookLinklist(Linklist):
html_fields = ['description']


class PageLinklist(Linklist):
""" Class to let linkcheck app discover fields containing links """
model = Page


class AuthorLinklist(Linklist):
""" Class to let linkcheck app discover fields containing links """
model = Author
Expand All @@ -31,6 +36,7 @@ def filter_callable(cls, objects):

linklists = {
'Books': BookLinklist,
'Pages': PageLinklist,
'Authors': AuthorLinklist,
'Journals': JournalLinklist,
}
7 changes: 7 additions & 0 deletions linkcheck/tests/sampleapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ def get_absolute_url(self):
return f"/book/{self.id}/"


class Page(models.Model):
book = models.ForeignKey(Book, on_delete=models.CASCADE)

def get_absolute_url(self):
return f"/book/{self.book.id}/{self.id}"


class Author(models.Model):
# This model has purposefully no get_absolute_url
name = models.CharField(max_length=50)
Expand Down
3 changes: 2 additions & 1 deletion linkcheck/tests/test_linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from linkcheck.models import Link, Url
from linkcheck.views import get_jquery_min_js

from .sampleapp.models import Author, Book, Journal
from .sampleapp.models import Author, Book, Journal, Page


@override_settings(ROOT_URLCONF='linkcheck.tests.urls')
Expand Down Expand Up @@ -967,6 +967,7 @@ class FixtureTestCase(TestCase):

def test_fixture(self):
self.assertEqual(Book.objects.count(), 1)
self.assertEqual(Page.objects.count(), 1)


class FilterCallableTestCase(TestCase):
Expand Down

0 comments on commit 5952085

Please sign in to comment.