Repository: internetarchive/openlibrary

Issue:
Errors submitting email via Contact Form
<!-- IMPORTANT: Before posting, be sure to redact or remove sensitive data, such as passwords, secret keys, session cookies, etc. -->
<!-- What problem are we solving? What does the experience look like today? What are the symptoms? -->

### Evidence / Screenshot (if possible)
<img width="736" alt="Screenshot 2024-02-21 at 12 45 15 PM" src="https://github.com/internetarchive/openlibrary/assets/978325/9b436ea2-6e00-4886-97af-7880426cf825">

### Relevant url?
https://openlibrary.org/contact
<!-- `https://openlibrary.org/...` -->
<img width="965" alt="Screenshot 2024-02-21 at 12 46 47 PM" src="https://github.com/internetarchive/openlibrary/assets/978325/48be4ba8-84a1-475a-9820-8b6c4dc3fa1b">

### Details

- **Logged in (Y/N)?** Y
- **Browser type/version?** Chrome
- **Operating system?** Mac
- **Environment (prod/dev/local)?** prod
<!-- If not sure, put prod -->

### Related files
<!-- Files related to this issue; this is super useful for new contributors who might want to help! If you're not sure, leave this blank; a maintainer will add them. -->

https://github.com/internetarchive/openlibrary/blob/master/openlibrary/plugins/openlibrary/support.py

### Hypothesis

Is it possible this change is affecting things?
https://github.com/internetarchive/openlibrary/commit/87cc320773021a2428017bebca2614cf4892327a#diff-215026b29c72c88ed72fa6d6eb105d7d2bc0c1a90a3b0ada9f3dcd23f100bed1R414

### Stakeholders
<!-- @ tag stakeholders of this bug -->



Discussion:
Update: Confirmed that this line seems to be the culprit:
https://github.com/internetarchive/openlibrary/blame/master/openlibrary/core/cache.py#L413-L414

As a proof of concept, I changed this line...
https://github.com/internetarchive/openlibrary/blob/master/openlibrary/plugins/openlibrary/support.py#L71

To: 
```
get_memcache().memcache.set('contact-POST-%s' % hashed_ip, "true", time=15 * MINUTE_SECS)
```
notice the get_memcache(). **memcache**
<img width="642" alt="Screenshot 2024-02-21 at 1 13 44 PM" src="https://github.com/internetarchive/openlibrary/assets/978325/1625b2e8-809e-4cc6-a53f-b4dd4f118e16">

Was able to fix this issue by noticing this blame:
https://github.com/internetarchive/openlibrary/blame/7e3faa7f9717f14bd39dc48ac035e0d4d4a3bb6c/openlibrary/core/cache.py#L413-L414

And applying this fix directly on plugins/openlibrary/support.py on testing:
```diff
- get_memcache().set('contact-POST-%s' % hashed_ip, "true", time=15 * MINUTE_SECS)
+ get_memcache().memcache.set('contact-POST-%s' % hashed_ip, "true", time=15 * MINUTE_SECS)
```
<img width="649" alt="Screenshot 2024-02-21 at 1 25 20 PM" src="https://github.com/internetarchive/openlibrary/assets/978325/d4e24d7c-255d-470a-963a-a615c20a734e">

<img width="972" alt="Screenshot 2024-02-21 at 1 24 26 PM" src="https://github.com/internetarchive/openlibrary/assets/978325/be893a57-bd51-4a7a-89f7-5c88a7fb27f5">

@cdrini I'm not sure what else would break if we reverted the core.cache.py changes back, so handing off to you for investigation!
After talking to @cdrini, everything seems right other than we just need to change `time` to `expires` in this call

Resolving patch:
diff --git a/openlibrary/plugins/openlibrary/support.py b/openlibrary/plugins/openlibrary/support.py
--- a/openlibrary/plugins/openlibrary/support.py
+++ b/openlibrary/plugins/openlibrary/support.py
@@ -68,7 +68,9 @@ def POST(self):
         message = SUPPORT_EMAIL_TEMPLATE % locals()
         sendmail(email, assignee, subject, message)
 
-        get_memcache().set('contact-POST-%s' % hashed_ip, "true", time=15 * MINUTE_SECS)
+        get_memcache().set(
+            'contact-POST-%s' % hashed_ip, "true", expires=15 * MINUTE_SECS
+        )
         return render_template("email/case_created", assignee)
 
 


Test patch: