From 1765b6ef2d6a63942e39e945a67622b0c912154d Mon Sep 17 00:00:00 2001 From: Hugh Rawlinson Date: Fri, 20 May 2022 23:11:50 +0200 Subject: [PATCH 1/3] Add option to ignore objects that fail to build --- src/wagtailbakery/views.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wagtailbakery/views.py b/src/wagtailbakery/views.py index 5ed967f..81206c3 100644 --- a/src/wagtailbakery/views.py +++ b/src/wagtailbakery/views.py @@ -91,8 +91,14 @@ def build_object(self, obj): self.request = RequestFactory( SERVER_NAME=site.hostname).get(self.get_url(obj)) self.set_kwargs(obj) - path = self.get_build_path(obj) - self.build_file(path, self.get_content(obj)) + try: + path = self.get_build_path(obj) + self.build_file(path, self.get_content(obj)) + except Exception as exc: + if settings.BAKERY_IGNORE_OBJECTS_THAT_FAILED_TO_BUILD: + logger.error("Failed to build object %s: %s" % (obj, exc)) + else: + raise exc def build_queryset(self): for item in self.get_queryset().all(): From 47289c135ea795dd2dbb0f560b4cc5d43bd892a9 Mon Sep 17 00:00:00 2001 From: Hugh Rawlinson Date: Thu, 16 Jun 2022 15:47:55 +0200 Subject: [PATCH 2/3] Document new config option --- README.md | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b1a5ef9..c6dc9e1 100644 --- a/README.md +++ b/README.md @@ -5,19 +5,19 @@ A set of helpers for baking your Django Wagtail site out as flat files. [![Build Status](https://travis-ci.org/wagtail/wagtail-bakery.svg?branch=master)](https://travis-ci.org/wagtail/wagtail-bakery) [![Coverage Status](https://coveralls.io/repos/github/wagtail/wagtail-bakery/badge.svg?branch=master)](https://coveralls.io/github/wagtail/wagtail-bakery?branch=master) -* Issues: [https://github.com/wagtail/wagtail-bakery/issues](https://github.com/wagtail/wagtail-bakery/issues) -* Testing: [https://travis-ci.org/wagtail/wagtail-bakery](https://travis-ci.org/wagtail/wagtail-bakery) -* Coverage: [https://coveralls.io/github/wagtail/wagtail-bakery](https://coveralls.io/github/wagtail/wagtail-bakery) +- Issues: [https://github.com/wagtail/wagtail-bakery/issues](https://github.com/wagtail/wagtail-bakery/issues) +- Testing: [https://travis-ci.org/wagtail/wagtail-bakery](https://travis-ci.org/wagtail/wagtail-bakery) +- Coverage: [https://coveralls.io/github/wagtail/wagtail-bakery](https://coveralls.io/github/wagtail/wagtail-bakery) Wagtail-bakery is built on top of [Django bakery](https://github.com/datadesk/django-bakery). Please read their [documentation](https://django-bakery.readthedocs.io/en/latest/) for detailed configuration and how to build default Django flat files. Yes. Wagtail-bakery is not limited to build Wagtail pages specifically, mixed content is possible! ## Features -* Single management command that will build your Wagtail site out as flat files -* Support for multisite, [theming](https://github.com/wagtail/wagtail-themes) and [multilingual](http://docs.wagtail.io/en/latest/advanced_topics/i18n/index.html) setup -* Support for `i18n_patterns` -* Support for generating a static API -* Ready to use Wagtail Buildable views to build all your (un)published pages at once (no extra code required!) +- Single management command that will build your Wagtail site out as flat files +- Support for multisite, [theming](https://github.com/wagtail/wagtail-themes) and [multilingual](http://docs.wagtail.io/en/latest/advanced_topics/i18n/index.html) setup +- Support for `i18n_patterns` +- Support for generating a static API +- Ready to use Wagtail Buildable views to build all your (un)published pages at once (no extra code required!) ## Installation @@ -79,6 +79,16 @@ BAKERY_VIEWS = ( The API views use Wagtail's V2 API module. To configure the data that is rendered by these views, please refer to Wagtail's [V2 API configuration guide](http://docs.wagtail.io/en/stable/advanced_topics/api/v2/configuration.html). +In case the static file for a page fails to build (for example, because the file +name would be too long for the filesystem's maximum file name length), you can +configure wagtail-bakery to ignore the page and continue to build the rest of +the static archive. The default behavior is that wagtail-bakery will throw the +error and stop the build. + +```py +BAKERY_IGNORE_OBJECTS_THAT_FAILED_TO_BUILD = True +``` + ## Usage Build the site out as flat files by running the `build` management command. @@ -140,6 +150,7 @@ Django/Wagtail combinations as [supported](http://docs.wagtail.io/en/latest/rele In order to keep for CI build time from growing out of control, not all Python/Django/Wagtail combinations will be tested. Test as follow: + - All supported Django/Wagtail combinations with the latest supported Python version. - The latest supported Django/Wagtail combination for the remaining Python versions. @@ -157,7 +168,7 @@ For issues [please submit an issue](https://github.com/wagtail/wagtail-bakery/is 1. Update `CHANGELOG.md`. 1. On GitHub, create a pull request and squash merge it. 1. Checkout and pull the `master` branch locally. -1. (Optional) If you need to verify anything, use `make publish-test` to upload to https://test.pypi.org and enter your PyPi *test* credentials as needed. +1. (Optional) If you need to verify anything, use `make publish-test` to upload to https://test.pypi.org and enter your PyPi _test_ credentials as needed. 1. Use `make publish` and enter your PyPi credentials as needed. 1. On GitHub, create a release and a tag for the new version. From c63597ac405c3c35bc0b3206c58d6e5d7b9be6c8 Mon Sep 17 00:00:00 2001 From: Hugh Rawlinson Date: Thu, 16 Jun 2022 15:51:28 +0200 Subject: [PATCH 3/3] Address PR comments --- src/wagtailbakery/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wagtailbakery/views.py b/src/wagtailbakery/views.py index 81206c3..9b5af2a 100644 --- a/src/wagtailbakery/views.py +++ b/src/wagtailbakery/views.py @@ -94,9 +94,9 @@ def build_object(self, obj): try: path = self.get_build_path(obj) self.build_file(path, self.get_content(obj)) - except Exception as exc: - if settings.BAKERY_IGNORE_OBJECTS_THAT_FAILED_TO_BUILD: - logger.error("Failed to build object %s: %s" % (obj, exc)) + except (OSError, AttributeError) as exc: + if getattr(settings, 'BAKERY_IGNORE_OBJECTS_THAT_FAILED_TO_BUILD', False): + logger.exception("Failed to build object %s: %s" % (obj, exc)) else: raise exc