Problem/Motivation

Some of the webforms we use on our site include uploaded documents/images. In the submission email we include a link to the uploaded file/image so the recipient can login, click the link and access the file.

Until recently (last couple of weeks) this worked fine. Now however the reference to the link no longer includes the real sid value but instead the placeholder text '_sid_'. As a result the file can't be accessed by clicking the link in the email since the link is incorrect.

This is what we used to have (and would like):
domain/system/files/webform/test_form/797/document.pdf

This is what we see now:
domain/system/files/webform/test_form/_sid_/document.pdf

The files are successfully stored in the a folder for the corresponding form with a sid value and the files can be also be accessed through the submissions page on the webform as expected.

Steps to reproduce

Create a simple form with a file upload
Edit the File field and under Advanced set the Submission display is set to Link or URL
Create an email handler to send the form to you on submission and include:
[webform_submission:values]
[webform_submission:sid]
Send a Test email

The resulting email will include the correct sid value for the [webform_submission:sid] but the URL of the file will have the placeholder '_sid_' instead of the real value.

Proposed resolution

Force webform submission attachments to be loaded from the DB.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

namscott created an issue. See original summary.

jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)
FileSize
5.53 KB

I am not able to replicate this issue using the attached webform.

Please provide a webform that can be used to replicate this issue.

skyhawk669’s picture

I am having the same issue. It worked well until today.

I have tested the attached webform and it also exhibits the problem on my live server. My test server is working fine, both with my forms as well as the attached form.

It sends an email with "_sid_" in the file URL instead of the actual sid. The weird thing is that if I go to the results page and resend the submission, then the URL is correct. It only happens during the initial email upon submitting the form.

I will be going over all the changes that have happened over the last few days and try to figure out what could be causing that issue on the live server but not the test server (they both have the same module versions installed).

jrockowitz’s picture

Version: 8.x-5.2 » 8.x-5.x-dev

The uploaded file's _sid_ is replaced via \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::postSave which calls \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::addFiles

The email is built and sent via \Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::postSave

Finally, WebformManagedFileBase::postSave is called before EmailWebformHandler::postSave
@see \Drupal\webform\WebformSubmissionStorage::doPostSave

I am not seeing any explanation for this regression and I can't reproduce it.

What version of Drupal and Webform are you using?

The ticket's version was currently set 8.x-5.2 but I am going to assume the issue is in latest dev release.

namscott’s picture

Version: 8.x-5.x-dev » 8.x-5.2

I am currently running Drupal 8.9.6 with Webform 5.22. But the problem started the release before, so still on 8.9.6 but with Webform5.21.

jrockowitz’s picture

The only change in the 5.22 release that could possibly cause this issue is #3173856: Sort handlers with the same weight by the handlers_id but this change has no impact on the triggering of the ::postSave callbacks.

skyhawk669’s picture

I am having the issue on Drupal 8.9.6 -8.9.7, using Webform 5.22, I tried Webform 6, same thing. Since the issue does not exist on my test server, there must be a setup difference between the two that I have not documented.

Thank you for explaining the process, I will do some debugging and see if I can figure out what is going on.

namscott’s picture

I think this may also be related, but I've set the 'Sanitize file name' setting and the link in the email includes the non-sanitized file name. But the sanitized filename is what is saved in the correct sid folder in the private folder. If this is something different I can open another issue.

This is the line fro the email with the file set to display as URL:

document
http://local.vm/system/files/webform/test_form/_sid_/5th-grade%20math-gr...

I tested the webform provided in #2 on my local system (no sanitization in this case) with the same outcome:

file
http://local.vm/system/files/webform/issue_3175525/_sid_/5th-grade%20mat...

jrockowitz’s picture

I don't think this santizing the file name is related to this issue.

namscott’s picture

I only wonder because the sanitization is actually working. It's just in the email it doesn't show the sanitized version of the name. It's like the email is sent before the file processing has finished.

jrockowitz’s picture

#4 documents that the file should uploaded, sanitized, and renamed before email is sent.

jrockowitz’s picture

Priority: Normal » Major

I am bumping the priority to Major.

namscott’s picture

I setup a new system to provide access for testing and when I tested the form it worked. This two systems have the same exact versions/setup for Drupal and Webform but they are different on the PHP/OS level.

The working system is running 7.3.18-1+ubuntu18.04.1+deb.sury.org+1 on Ubuntu 18.04.4 LTS.

The system having trouble is 7.3.20 on CentOS Linux 7 (Core)

skyhawk669’s picture

Priority: Major » Normal

I have been chasing my tail trying to figure out what might be going on. All I have found so far is that the files are getting moved and renamed correctly, but when the tokens are being replaced and the file entity is loaded, it contains the old info before the move.

If for example if at the very end of \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::addFiles, I reload the file (using $this->entityTypeManager->getStorage('file')->load($fids[0])) it still outputs the URI/name before the changes were made.

If I do a database query at this same spot, it pulls the correct information, so I figured maybe it was a problem with the static cache not getting cleared? But it made no difference when I forced it to clear.

If I go to the submission page and resend the email, then the link to the file in the email is working properly, so at that stage the token replace function is able to load the file entity with the correct info.

I am not sure what could be causing this at this stage, considering I had not changed or upgraded anything when the error started happening.

skyhawk669’s picture

Priority: Normal » Major

Sorry, didn't mean to change the priority.

jrockowitz’s picture

Version: 8.x-5.2 » 8.x-5.22

@skyhawk669 Does the issue go away if you download grade from 5.22 to 5.21?

skyhawk669’s picture

Version: 8.x-5.22 » 8.x-5.2

@jrockowitz I currently am on 6.0.0-alpha20. I was on 5.22 originally, but I had upgraded just in case that fixed it, which it did not. Is it possible to downgrade back down to 5.21?

I have not been able to reproduce the problem on any of my test servers, so I assume the issue must be outside of Webform, or some sort of interaction with another system. I do have memcached running on production but not on my test server, I will go ahead an try this.

skyhawk669’s picture

OK, after installing memcache 2.2 on my test server I can reproduce the problem! @namscott are you using any sort of caching as well?

namscott’s picture

We are running memcache (Memcached v3.1.5) as well as varnish (on production only). I do have varnish installed on my local but not running and I'm still seeing the issue with varnish not running so I thought it wouldn't be a factor. Both memcache and varnish are not enabled on my test system which is working fine.

skyhawk669’s picture

I use memcached and varnish on production as well. I enabled memcached on my test server and it now exhibits the same issue. For me, the problem started after upgrading to drupal/memcache 2.2. Downgrading to 2.1 solved the issue on my server. This bug is being caused by this change: https://www.drupal.org/project/memcache/issues/2996615

So it looks like something that needs to be fixed by the memcache module maintainers, it is not a Webform issue.

jrockowitz’s picture

I can was able to replicate this issue when enabling and configuring Memcache 2.2.

I am not sure if the Webform module can provide a workaround.

We could warn people using Memcache 2.2 and assume the issue will solved in Memcache 2.3

jrockowitz’s picture

Version: 8.x-5.2 » 8.x-5.x-dev
Status: Postponed (maintainer needs more info) » Needs review
FileSize
860 bytes

Resetting the single file cache did not work for me but resetting the entire file entities cache does solve the problem but this is not a great solution.

jrockowitz’s picture

@skyhawk669 Thanks for figuring out the source of this issue.

jrockowitz’s picture

Attached is a slightly better patch but using \Drupal::entityTypeManager()->getStorage('file')->resetCache($fids); does not work as expected.

namscott’s picture

Thanks to both of you for figuring out the source of the problem.

jrockowitz’s picture

Since over 8000 sites have already upgrade to Memcache 2.2. The only thing that I think we can do is warn users about this major regression via Drupal's Status report (/admin/reports/status).

  • jrockowitz authored 2c38930 on 8.x-5.x
    Issue #3175525 by jrockowitz: Email link to file includes '_sid_' rather...
jrockowitz’s picture

Status: Needs review » Closed (duplicate)

Adding a warning is our only option, so I committed the patch.

Otherwise this issue needs to be addressed via #3176519: Uploaded files not linking correctly in emails sent through Webform module after upgrading to memcache 2.2

jibran’s picture

FWIW, the following patch fixed the issue for a client site using CloudFront instead of Memcache.

jrockowitz’s picture

Status: Closed (duplicate) » Needs review

The patch seems like the right solution. Let's see if all tests are still passing.

jrockowitz’s picture

Attached patch changes

$this->entityTypeManager->getStorage('file')->resetCache();
    return $this->entityTypeManager->getStorage('file')->loadMultiple((array) $value);

to

    $fids = (array) $value;
    $this->entityTypeManager->getStorage('file')->resetCache($fids);
    return $this->entityTypeManager->getStorage('file')->loadMultiple($fids);
jibran’s picture

Status: Needs review » Needs work

Yeah, that is a good idea. We need to revert #26 so NW for that. Do you think we can add some tests for this?

jrockowitz’s picture

I am not sure how much test coverage we can add and maybe it is not absolutely needed.

The patch makes sense to me.

jibran’s picture

Status: Needs work » Reviewed & tested by the community

Yeah, I had the same idea. I think #26 can be removed on commit so setting it to RTBC.

jibran’s picture

Added proposed resolution to IS.

  • jrockowitz authored 20d61f2 on 8.x-5.x
    Issue #3175525 by jrockowitz, jibran: Email link to file includes '_sid_...

  • jrockowitz authored 20d61f2 on 6.x
    Issue #3175525 by jrockowitz, jibran: Email link to file includes '_sid_...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jedgar1mx’s picture

I get an error when applying #31 to version 6.0
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2021-01-14/3175525-31.patch

jedgar1mx’s picture

double post error sorry

JosephAM’s picture

I'm still experiencing this issue, even after the patch.

Drupal: 8.9.13
Memcache module: 2.2
Webform: 8.x-5.12

I wondered if the patch + other updates in 8.x-5.x might have fixed it, but even after removing the patch and upgrading to 8.x-5.24 (which contains the patched code), I am still experiencing the _sid_ problem. Not only is this affecting links to files, but also attachments via Mail System + Swiftmailer.

FWIW, here are the bins I have configured for memcache:

$settings['cache']['bins']['bootstrap'] = 'cache.backend.memcache';
$settings['cache']['bins']['discovery'] = 'cache.backend.memcache';
$settings['cache']['bins']['config'] = 'cache.backend.memcache';
$settings['cache']['bins']['default'] = 'cache.backend.memcache';
$settings['cache']['bins']['render'] = 'cache.backend.memcache';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.memcache';
$settings['cache']['default'] = 'cache.backend.memcache';

ayalon’s picture

We also still have the same issue. The upload is working, but the issue remains in the mail template. Downgrading to memcache 2.1 solves the issue.

peonboyos’s picture

Yes, same here.
It's still happening

Drupal: 8.9.13
Memcache module: 2.2
Webform: 8.x-5.24

Downgrade to memcache 2.1 fix the issue.

didaka’s picture

Same here. I had to downgrade the memchace module. The issue should be reopened.

richardbporter’s picture

Yes still happening on Drupal 9.1.4, webform 6.0.1 and Memache 2.2. I'm not familiar with this functionality but in debugging it seems like WebformManagedFileBase::getFileDestinationUri replaces the _sid_ string in the destination correctly so I'm confused why its still in the email body.

sime’s picture

The upgrade failed for us. We noticed the patch that we were using differs to what was applied to the module. This patch fixes it for us.

jrockowitz’s picture

If $this->entityTypeManager->getStorage('file')->resetCache(); is called the file entity cache will be reset with every file upload which could impact a website's performance.

I think this issue was addressed via https://www.drupal.org/project/memcache/releases/8.x-2.3

sime’s picture

We don't use memcache. We use redis if that helps.
We have not dived into why this is still an issue for us, but for now that patch keeps us running.

richardbporter’s picture

Updating memcache to 8.2.3 fixed it for us.

jedgar1mx’s picture

new memcache version fixes issue

gordon’s picture

FileSize
1.17 KB

I rerolled the patch to apply to 6.2