Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QR-Code generation fails if the short url is not enabled #1960

Closed
Laurendus opened this issue Dec 21, 2023 · 2 comments · Fixed by #1962
Closed

QR-Code generation fails if the short url is not enabled #1960

Laurendus opened this issue Dec 21, 2023 · 2 comments · Fixed by #1962
Labels
Milestone

Comments

@Laurendus
Copy link

Shlink version

3.7.1

PHP version

8.2.13

How do you serve Shlink

RoadRunner Docker image

Database engine

PostgreSQL

Database version

15.3

Current behavior

I create a short url with an 'enabled since' date which lies in the future.
I then try to create a qr-code. The call fails with:

shlink-app-1  | REDACTED	INFO	server      	[REDACTED] [REDACTED] Shlink.WARNING - An error occurred while creating QR code. 
shlink-app-1  | Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException: No URL found with short code "REDACTED" for domain "REDACTED" in /etc/shlink/module/Core/src/Exception/ShortUrlNotFoundException.php:27
shlink-app-1  | Stack trace:
shlink-app-1  | #0 /etc/shlink/module/Core/src/ShortUrl/ShortUrlResolver.php(47): Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException::fromNotFound(Object(Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier))
shlink-app-1  | #1 /etc/shlink/module/Core/src/Action/QrCodeAction.php(36): Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolver->resolveEnabledShortUrl(Object(Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier))
shlink-app-1  | #2 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(26): Shlinkio\Shlink\Core\Action\QrCodeAction->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #3 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #4 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(75): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #5 /etc/shlink/vendor/mezzio/mezzio-router/src/Route.php(79): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #6 /etc/shlink/vendor/mezzio/mezzio-router/src/RouteResult.php(109): Mezzio\Router\Route->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #7 /etc/shlink/vendor/mezzio/mezzio-router/src/Middleware/DispatchMiddleware.php(32): Mezzio\Router\RouteResult->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #8 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(26): Mezzio\Router\Middleware\DispatchMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #9 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #10 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(75): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #11 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #12 /etc/shlink/vendor/laminas/laminas-stratigility/src/Middleware/PathMiddlewareDecorator.php(42): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #13 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Laminas\Stratigility\Middleware\PathMiddlewareDecorator->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #14 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(42): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #15 /etc/shlink/vendor/mezzio/mezzio-router/src/Middleware/ImplicitHeadMiddleware.php(77): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #16 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(26): Mezzio\Router\Middleware\ImplicitHeadMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #17 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #18 /etc/shlink/vendor/mezzio/mezzio-router/src/Middleware/RouteMiddleware.php(50): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #19 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(26): Mezzio\Router\Middleware\RouteMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #20 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #21 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(75): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #22 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #23 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(42): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #24 /etc/shlink/vendor/shlinkio/shlink-common/src/Middleware/CloseDbConnectionMiddleware.php(24): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #25 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(26): Shlinkio\Shlink\Common\Middleware\CloseDbConnectionMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #26 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #27 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(75): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #28 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #29 /etc/shlink/vendor/laminas/laminas-stratigility/src/Middleware/PathMiddlewareDecorator.php(42): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #30 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Laminas\Stratigility\Middleware\PathMiddlewareDecorator->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #31 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(42): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #32 /etc/shlink/module/Rest/src/Middleware/CrossDomainMiddleware.php(24): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #33 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(26): Shlinkio\Shlink\Rest\Middleware\CrossDomainMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #34 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #35 /etc/shlink/vendor/laminas/laminas-stratigility/src/Middleware/ErrorHandler.php(129): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #36 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(26): Laminas\Stratigility\Middleware\ErrorHandler->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #37 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #38 /etc/shlink/vendor/php-middleware/request-id/src/RequestIdMiddleware.php(32): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #39 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(26): PhpMiddleware\RequestId\RequestIdMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #40 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #41 /etc/shlink/vendor/shlinkio/shlink-common/src/Middleware/ContentLengthMiddleware.php(24): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #42 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(26): Shlinkio\Shlink\Common\Middleware\ContentLengthMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #43 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #44 /etc/shlink/vendor/shlinkio/shlink-common/src/Middleware/AccessLogMiddleware.php(26): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #45 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(26): Shlinkio\Shlink\Common\Middleware\AccessLogMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #46 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #47 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(75): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #48 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(49): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
shlink-app-1  | #49 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(75): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #50 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(64): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\EmptyPipelineHandler))
shlink-app-1  | #51 /etc/shlink/vendor/mezzio/mezzio/src/Application.php(34): Laminas\Stratigility\MiddlewarePipe->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #52 /etc/shlink/bin/roadrunner-worker.php(24): Mezzio\Application->handle(Object(Laminas\Diactoros\ServerRequest))
shlink-app-1  | #53 /etc/shlink/bin/roadrunner-worker.php(32): {closure}()
shlink-app-1  | #54 {main}
shlink-app-1  | 
shlink-app-1  | REDACTED	INFO	server      	[REDACTED] [REDACTED] Access.INFO - GET /REDACTED/qr-code?size=300&format=png&errorCorrection=L 404 979

Expected behavior

I expected it to create the qr-code even before the url is enabled so that I am able to use the beneficial method of sharing via qr-code.

How to reproduce

Create a short url with an 'enabled since' date lying in the future.
Try to create a qr-code.

@acelaya
Copy link
Member

acelaya commented Dec 22, 2023

Thanks for reporting.

This is a tricky one. I never thought about this, so I guess it's fair to consider it a bug.

However, there might be people relying on this buggy behavior, and changing it would break the experience for them.

Probably, the best course of action here is to add a new config option which tells Shlink how to behave for "disabled" short URLs.

This option would be released in Shlink 3.7.2, keeping existing behavior by default (QR code generation would fail while URLs are disabled), but allowing to opt-in to a behavior where QR code generation never fails.

Shlink 4.0.0 would change default behavior to always generate QR codes regardless of the URL configuration, and allow to opt-in to make it fail for disabled URLs (as this is how I think it should work).

This is open to change once I start working on it, as there might be some reason for things to be like this, that I'm missing now.

As a temporary workaround, you can remove the start date, generate the QR code, and then add the start date back. The QR code won't change, and the URL on it will work once the start date is reached.

@acelaya acelaya added this to the 3.7.2 milestone Dec 22, 2023
@acelaya acelaya moved this to Todo in Shlink Dec 22, 2023
@acelaya acelaya changed the title QR-Code generation fails if the short url is not yet enabled QR-Code generation fails if the short url is not enabled Dec 23, 2023
@acelaya acelaya moved this from Todo to In Progress in Shlink Dec 24, 2023
@acelaya acelaya moved this from In Progress to In review in Shlink Dec 24, 2023
@github-project-automation github-project-automation bot moved this from In review to Done in Shlink Dec 24, 2023
@acelaya
Copy link
Member

acelaya commented Dec 24, 2023

This is now implemented. I will release v3.7.2 after Christmas.

This version supports a new QR_CODE_FOR_DISABLED_SHORT_URLS=true env var which will make QR code generation work even for disabled short URLs.

The same config option is also supported via installation tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants