Skip to content

Conversation

escopecz
Copy link
Member

@escopecz escopecz commented Mar 3, 2025

Q A
Bug fix? (use the a.b branch) [y]
New feature/enhancement? (use the a.x branch) [ ]
Deprecations? [ ]
BC breaks? (use the c.x branch) [ ]
Automated tests included? [y]
Related user documentation PR URL mautic/mautic-documentation#...
Related developer documentation PR URL mautic/developer-documentation#...
Issue(s) addressed Fixes /

Description:

This PR resolves this error:

500 Internal Server Error - Call to a member function getId() on null 
/app/bundles/AssetBundle/Model/AssetModel.php:272 at
/app/bundles/AssetBundle/Controller/PublicController.php:89 at Mautic\AssetBundle\Model\AssetModel -> trackDownload ( null, object(Request), '404' )
/vendor/symfony/http-kernel/HttpKernel.php:169 at Mautic\AssetBundle\Controller\PublicController -> downloadAction ( 'unicorn' )
/vendor/symfony/http-kernel/HttpKernel.php:81 at Symfony\Component\HttpKernel\HttpKernel -> handleRaw ( object(Request), '1' )
/vendor/symfony/http-kernel/Kernel.php:201 at Symfony\Component\HttpKernel\HttpKernel -> handle ( object(Request), '1', true )
/app/AppKernel.php:103 at Symfony\Component\HttpKernel\Kernel -> handle ( object(Request), '1', true )
/app/middlewares/CORSMiddleware.php:82 at AppKernel -> handle ( object(Request), '1', true )
/app/middlewares/CatchExceptionMiddleware.php:34 at Mautic\Middleware\CloudMiddleware -> handle ( object(Request), '1', true )
/app/middlewares/Dev/IpRestrictMiddleware.php:52 at Mautic\Middleware\CatchExceptionMiddleware -> handle ( object(Request), '1', true )
/app/middlewares/VersionCheckMiddleware.php:58 at Mautic\Middleware\Dev\IpRestrictMiddleware -> handle ( object(Request), '1', true )
/app/middlewares/TrustMiddleware.php:42 at Mautic\Middleware\VersionCheckMiddleware -> handle ( object(Request), '1', true )
/vendor/stack/builder/src/Stack/StackedHttpKernel.php:23 at Mautic\Middleware\TrustMiddleware -> handle ( object(Request), '1', true )
/vendor/stack/run/src/Stack/run.php:13 at Stack\StackedHttpKernel -> handle ( object(Request) )
/index_dev.php:25 at Stack\run ( object(StackedHttpKernel) )

It happens when a contact is trying to download an asset that do not exist.

From the behavior change perspective, this is how the contact history was before this change:
Screenshot 2025-01-09 at 09 48 47

The consecutive asset download records couldn't be shown as it ended up with the 500 error. The first request worked only if the contact device wasn't tracked yet.

This is how it looks with this change:
Screenshot 2025-01-09 at 09 52 41

Now the consecutive tries to download the asset will be tracked.

Notes about 404 tracking

If you wish to track the 404 attempts for download then make sure you have a 404 custom page selected and 404 page tracking enabled if you want to track the first tracking requests for anonymous contacts.

Screenshot 2025-02-13 at 16 46 15
Screenshot 2025-02-13 at 16 45 21

Steps to test

  1. Access https://mautic.ddev.site/asset/unicorn (on your Mautic instance you test with) as an anonymous contact. The unicorn asset alias should not exist so it will replicate the 500 error. If it does exist, you live is so, so amazing! 🦄
  2. I found out that you must access this route twice or more to trigger this error. It happens only if the device is already tracked.

Other areas of Mautic that may be affected by the change:

  1. Just asset download

List deprecations along with the new alternative:

  1. None

List of areas covered by the unit and/or functional tests:

  1. The functional test is testing accessing a download page for not existing asset twice and checks that it returns 404 code for the second time.

@escopecz escopecz added bug Issues or PR's relating to bugs assets Anything related to assets unforking Used for PRs in the Acquia's unforking initiative labels Mar 3, 2025
@escopecz escopecz added this to the 5.2.4 milestone Mar 3, 2025
@escopecz escopecz requested review from a team, rohitpavaskar and aarohiprasad and removed request for a team March 3, 2025 10:22
@escopecz escopecz added ready-to-test PR's that are ready to test code-review-needed PR's that require a code review before merging labels Mar 3, 2025
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.65%. Comparing base (8f3bf67) to head (4fa2b7b).
Report is 9 commits behind head on 5.2.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                5.2   #14663   +/-   ##
=========================================
  Coverage     63.65%   63.65%           
+ Complexity    34657    34656    -1     
=========================================
  Files          2273     2273           
  Lines        103685   103684    -1     
=========================================
+ Hits          65998    65999    +1     
+ Misses        37687    37685    -2     
Files with missing lines Coverage Δ
...undles/AssetBundle/Controller/PublicController.php 74.28% <ø> (+4.84%) ⬆️
app/bundles/AssetBundle/Model/AssetModel.php 50.71% <100.00%> (ø)
🚀 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.

@escopecz escopecz moved this to 🦸🏻 Needs 2 tests in Open Source Fridays Mar 3, 2025
@escopecz escopecz requested a review from Copilot March 5, 2025 10:38
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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

@escopecz escopecz moved this from 🦸🏻 Needs 2 tests to ⏳︎ Needs 1 more test in Open Source Fridays Mar 6, 2025
@aarohiprasad
Copy link
Contributor

Working as expected. Thanks @escopecz!

@aarohiprasad aarohiprasad added ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged and removed ready-to-test PR's that are ready to test code-review-needed PR's that require a code review before merging labels Mar 11, 2025
Copy link
Contributor

@aarohiprasad aarohiprasad left a comment

Choose a reason for hiding this comment

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

image

@aarohiprasad aarohiprasad moved this from ⏳︎ Needs 1 more test to 🎉 Ready to commit in Open Source Fridays Mar 11, 2025
@escopecz escopecz merged commit dd393df into mautic:5.2 Mar 11, 2025
17 checks passed
@github-project-automation github-project-automation bot moved this from 🎉 Ready to commit to 🥳 Done in Open Source Fridays Mar 11, 2025
@escopecz escopecz changed the title Asset 404 fix Fixing a 500 error when an asset was not found Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assets Anything related to assets bug Issues or PR's relating to bugs ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged unforking Used for PRs in the Acquia's unforking initiative
Projects
Status: 🥳 Done
Development

Successfully merging this pull request may close these issues.

3 participants