Skip to content

Cumulative backport to 5.1.x of GWC PRs#14379

Merged
etj merged 3 commits into
5.1.xfrom
14306_14358_51x_gwc
Jun 23, 2026
Merged

Cumulative backport to 5.1.x of GWC PRs#14379
etj merged 3 commits into
5.1.xfrom
14306_14358_51x_gwc

Conversation

@etj

@etj etj commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This PR contains the backport of some PRs that failed to be automatically backported:

Checklist

Reviewing is a process done by project maintainers, mostly on a volunteer basis. We try to keep the overhead as small as possible and appreciate if you help us to do so by completing the following items. Feel free to ask in a comment if you have troubles with any of them.

For all pull requests:

  • Confirm you have read the contribution guidelines
  • You have sent a Contribution Licence Agreement (CLA) as necessary (not required for small changes, e.g., fixing typos in the documentation)
  • Make sure the first PR targets the master branch, eventual backports will be managed later. This can be ignored if the PR is fixing an issue that only happens in a specific branch, but not in newer ones.

The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):

  • There is a ticket in https://github.com/GeoNode/geonode/issues describing the issue/improvement/feature (a notable exemption is, changes not visible to end-users)
  • The issue connected to the PR must have Labels and Milestone assigned
  • PR for bug fixes and small new features are presented as a single commit
  • PR title must be in the form "[Fixes #<issue_number>] Title of the PR"
  • New unit tests have been added covering the changes, unless there is an explanation on why the tests are not necessary/implemented

Submitting the PR does not require you to check all items, but by the time it gets merged, they should be either satisfied or inapplicable.

@etj etj requested a review from giohappy June 23, 2026 09:03
@etj etj self-assigned this Jun 23, 2026
Copilot AI review requested due to automatic review settings June 23, 2026 09:03
@cla-bot cla-bot Bot added the cla-signed CLA Bot: community license agreement signed label Jun 23, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the GWC tile layer creation command by deprecating the old create_tile_layers command and integrating it as a subcommand under the unified gwc command. It also updates GWCClient with GET and PUT methods, introduces an XML template for layer creation, and adds support for dry-run and debug modes. Feedback has been provided to improve error handling and resilience in the new create subcommand, specifically by moving the layer retrieval call inside the try...except block to prevent crashes on network failures, handling undefined variables during dry runs, and filtering out empty layer names to avoid potential TypeErrors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +110 to +134
r = gwc.get_layer(layername)
if r.status_code == 200:
if force:
logger.info(" - Forcing layer configuration in GWC")
cnt_force += 1
else:
logger.info(f" - Layer already configured in GWC (code {r.status_code})")
cnt_old += 1
continue
try:
logger.info(" - Configuring...")
data = self.generate_xml(template, layername)
if not dry_run:
response = gwc.set_layer(layername, data=data)

if dry_run or response.status_code == 200:
logger.info(f" - Done {layername}")
cnt_new += 1
else:
logger.warning(f"Layer {layername} couldn't be configured: code {response.status_code}")
cnt_bad += 1

except Exception as e:
logger.warning(f"Error processing {layername}: {e}")
cnt_bad += 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The gwc.get_layer(layername) call is currently placed outside the try...except block. If any network timeout, connection error, or API failure occurs during this call, the entire management command will crash and terminate immediately, rather than logging the error and continuing to process the remaining layers. Moving this call inside the try...except block makes the loop much more resilient. Additionally, initializing response = None and checking response before accessing response.status_code prevents potential NameError or AttributeError when dry_run is True.

            try:
                r = gwc.get_layer(layername)
                if r.status_code == 200:
                    if force:
                        logger.info("  - Forcing layer configuration in GWC")
                        cnt_force += 1
                    else:
                        logger.info(f"  - Layer already configured in GWC (code {r.status_code})")
                        cnt_old += 1
                        continue

                logger.info("  - Configuring...")
                data = self.generate_xml(template, layername)
                response = None
                if not dry_run:
                    response = gwc.set_layer(layername, data=data)

                if dry_run or (response and response.status_code == 200):
                    logger.info(f"  - Done {layername}")
                    cnt_new += 1
                else:
                    status_code = response.status_code if response else "N/A"
                    logger.warning(f"Layer {layername} couldn't be configured: code {status_code}")
                    cnt_bad += 1

            except Exception as e:
                logger.warning(f"Error processing {layername}: {e}")
                cnt_bad += 1

Comment on lines +93 to +97
if create_all:
datasets_fields = Dataset.objects.values_list('typename', 'alternate')
layer_names = [typename or alternate for typename, alternate in datasets_fields]
else:
layer_names = requested_layers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If create_all is True, Dataset.objects.values_list('typename', 'alternate') is queried. If any dataset has both fields as None or empty, it will add None to layer_names, which subsequently causes a TypeError in _validate_layer_name. Filtering out falsy values prevents this. Additionally, if requested_layers is None (the default) and create_all is False, layer_names will be None, causing len(layer_names) to raise a TypeError. Defaulting to an empty list requested_layers or [] ensures robustness.

Suggested change
if create_all:
datasets_fields = Dataset.objects.values_list('typename', 'alternate')
layer_names = [typename or alternate for typename, alternate in datasets_fields]
else:
layer_names = requested_layers
if create_all:
datasets_fields = Dataset.objects.values_list('typename', 'alternate')
layer_names = [typename or alternate for typename, alternate in datasets_fields if typename or alternate]
else:
layer_names = requested_layers or []

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Backports GWC-related improvements to the 5.1.x branch by expanding the gwc management command into a subcommand-based interface and aligning tile-layer creation with an XML template, while deprecating the legacy create_tile_layers command.

Changes:

  • Add gwc create subcommand and refactor gwc truncate into a subparser-based CLI with shared --dry-run/--debug flags.
  • Introduce a templated XML-driven tile-layer creation workflow (gwc_subcommands/create.py + create_template.xml).
  • Extend GWCClient with REST helpers (GET/PUT) and layer get/set operations; route deprecated create_tile_layers to the new implementation.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
geonode/geoserver/management/commands/gwc.py Converts gwc into a subcommand-based CLI and wires create + truncate.
geonode/geoserver/management/commands/gwc_subcommands/truncate.py Moves truncate argument parsing into the subcommand module and adds dry-run/debug plumbing.
geonode/geoserver/management/commands/gwc_subcommands/create.py Adds tile-layer creation subcommand using an XML template and new GWCClient methods.
geonode/geoserver/management/commands/gwc_subcommands/create_template.xml Adds/aligns the GWC layer XML template (gridsets + metatiling).
geonode/geoserver/gwc.py Adds debug-aware REST helpers plus get_layer/set_layer.
geonode/br/management/commands/create_tile_layers.py Deprecates the legacy command and dispatches to gwc create implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +93 to +97
if create_all:
datasets_fields = Dataset.objects.values_list('typename', 'alternate')
layer_names = [typename or alternate for typename, alternate in datasets_fields]
else:
layer_names = requested_layers
force = options.get('force')
requested_layers = options.get('layers')
dry_run = options.get('dry-run')
logger.error("THIS COMMAND IS DEPRECATED - USE THE gwc COMMAND INSTEAD")
Comment on lines +67 to +71
def handle(self, **options):
dry_run = options.get('dry-run')
debug = options.get('debug')
setup_logger(level=logging.DEBUG if debug else logging.INFO)

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 38.69048% with 103 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (5.1.x@f537413). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff            @@
##             5.1.x   #14379   +/-   ##
========================================
  Coverage         ?   74.80%           
========================================
  Files            ?      984           
  Lines            ?    60525           
  Branches         ?     8268           
========================================
  Hits             ?    45275           
  Misses           ?    13399           
  Partials         ?     1851           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@giohappy giohappy changed the title Cumulative backport to 5.1.x of GWC PRs - REBASE, DO NOT SQUASH Cumulative backport to 5.1.x of GWC PRs Jun 23, 2026
@etj etj merged commit ed585c0 into 5.1.x Jun 23, 2026
14 checks passed
@etj etj deleted the 14306_14358_51x_gwc branch June 23, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed CLA Bot: community license agreement signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants