With $.Paginator error in Hugo 0.123.8

Hi,
The post from August 2021

concluded with the solution from which I took a part of a code to my site:

  {{ $href := .Permalink }}
    {{ with $.Paginator }}
      {{ if gt .PageNumber 1 }}
      {{ $href = .URL | absURL }}
      {{ end }}
  {{ end }}
  <link rel="canonical" href="{{ $href }}">

I know that there were some breaking changes in 0.123 Hugo but unable to quicly reference it to the above code which return

execute of template failed: template: partials/head.html:50:13: executing "partials/head.html" at <$.Paginator>: error calling Paginator: pagination not supported for this page: kind: "page", path:

Any help appreciated.

Fixed replacing:

{{ with $.Paginator }}

with

{{ with and .Page.IsNode .Paginator }}

As suggested here:

Can just somebody verify that this is right approach before I click resolved?

and Returns the first falsy argument. If all arguments are truthy, returns the last argument.

Seems OK if the paginator is the last one argument.

Be careful when using .IsNode. It returns true when used in the 404 template (see #12162). And if you’re not careful you might end up doing this:

https://github.com/gohugoio/hugo/issues/12192