internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: bookwyrm-social/bookwyrm

Issue:
Server error on some book imports
**Describe the bug**
When importing some books the application crashes, with "Server Error Something went wrong! Sorry about that."
```
Internal Server Error: /resolve-book
Traceback (most recent call last):
  File "/opt/bookwyrm/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/opt/bookwyrm/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/bookwyrm/venv/lib/python3.10/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/opt/bookwyrm/venv/lib/python3.10/site-packages/django/views/decorators/http.py", line 40, in inner
    return func(request, *args, **kwargs)
  File "/opt/bookwyrm/bookwyrm/views/books/books.py", line 190, in resolve_book
    return redirect("book", book.id)
AttributeError: 'NoneType' object has no attribute 'id'
```



Discussion:
Noting this here as a book that has triggered this bug: https://inventaire.io/entity/wd:Q3294970
This does seem a bit random. Sometimes a particular book will cause it but then try again with the same book and it works.
I have the same error (with the aforementioned specific book as an example, https://inventaire.io/entity/wd:Q3294970

the book is apparently successfully imported, despite the error page. it can be found in the bookwyrm instance later as an imported book. had this happen with several inventaire imports, but not any others (out of maybe 10 or so)

Resolving patch:
diff --git a/bookwyrm/connectors/inventaire.py b/bookwyrm/connectors/inventaire.py
--- a/bookwyrm/connectors/inventaire.py
+++ b/bookwyrm/connectors/inventaire.py
@@ -165,8 +165,8 @@ def create_edition_from_data(self, work, edition_data, instance=None):
                 edition_data = self.get_book_data(edition_data)
             except ConnectorException:
                 # who, indeed, knows
-                return
-        super().create_edition_from_data(work, edition_data, instance=instance)
+                return None
+        return super().create_edition_from_data(work, edition_data, instance=instance)
 
     def get_cover_url(self, cover_blob, *_):
         """format the relative cover url into an absolute one:


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Add review count to book search listing to concentrate reviews
Often when I'm searching for a book to e.g. mark as having started reading, or to figure out if any other wyrms have reviewed it, I'll have more than one search result. 

![image](https://user-images.githubusercontent.com/3862362/196053166-f31dc917-15d7-411e-8249-97706cdb5869.png)
_two results for wayfarer no 2_

I typically don't really care so much about reviewing a given edition (I read a lot of non-scholarly ebooks). So instead of finding a particular edition, I want to find the one that has been reviewed by people I follow & whose judgement I trust. Similarly, I'd want to contribute _my_ review to that growing pile of context around a given book.

To aid this, I suggest adding some light information markers to the search results. # of reviews would be one concrete suggestions, another would be to display which ones people I'm following have reviewed. Basically use whatever makes sense from a fast query perspective imo :)

Thanks again for bookwyrm! It's a delightful space and I've found _so_ many books over the soon-to-be 2 years since I joined!! u rok


Discussion:
This is such a good idea! Thank you

Resolving patch:
diff --git a/bookwyrm/templatetags/book_display_tags.py b/bookwyrm/templatetags/book_display_tags.py
--- a/bookwyrm/templatetags/book_display_tags.py
+++ b/bookwyrm/templatetags/book_display_tags.py
@@ -1,10 +1,17 @@
 """ template filters """
 from django import template
+from bookwyrm import models
 
 
 register = template.Library()
 
 
+@register.filter(name="review_count")
+def get_review_count(book):
+    """how many reviews?"""
+    return models.Review.objects.filter(deleted=False, book=book).count()
+
+
 @register.filter(name="book_description")
 def get_book_description(book):
     """use the work's text if the book doesn't have it"""


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
AASIN and isfdb not editable
Somehow during the merge some code most be gone lost because...

<img width="640" alt="Bildschirm­foto 2022-12-11 um 21 29 47" src="https://user-images.githubusercontent.com/2017105/206927195-f9b27bcc-2f3a-46eb-ab1d-84340e5fa061.png">



Discussion:
Oh dear! I know exactly what happened, it was a merge weirdness with another PR of mine; I'll fix it momentarily

Resolving patch:
diff --git a/bookwyrm/forms/books.py b/bookwyrm/forms/books.py
--- a/bookwyrm/forms/books.py
+++ b/bookwyrm/forms/books.py
@@ -40,6 +40,8 @@ class Meta:
             "goodreads_key",
             "oclc_number",
             "asin",
+            "aasin",
+            "isfdb",
         ]
         widgets = {
             "title": forms.TextInput(attrs={"aria-describedby": "desc_title"}),


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Open Graph tag support for lists
**Is your feature request related to a problem? Please describe.**

When I add a link to [a list](https://bookwyrm.social/list/935/s/book-club-of-two) in e.g. Slack (probably Mastodon/Twitter too?) I get a generic "card" like this:

<img width="414" alt="Screen Shot 2023-01-05 at 12 15 42 PM" src="https://user-images.githubusercontent.com/391371/210841547-ad1e810e-cbd9-476a-9642-0de1670892a3.png">

**Describe the solution you'd like**

If I'm linking to a list, it would be useful to have list-specific info:
- name of the list
- description
- created/curated by
- maybe number of books?



Discussion:
This is good idea! I changed the title slightly so I'd remember what the suggestion was better

Resolving patch:
diff --git a/bookwyrm/templatetags/list_page_tags.py b/bookwyrm/templatetags/list_page_tags.py
new file mode 100644
--- /dev/null
+++ b/bookwyrm/templatetags/list_page_tags.py
@@ -0,0 +1,25 @@
+""" template filters for list page """
+from django import template
+from django.utils.translation import gettext_lazy as _, ngettext
+
+from bookwyrm import models
+
+
+register = template.Library()
+
+
+@register.filter(name="opengraph_title")
+def get_opengraph_title(book_list: models.List) -> str:
+    """Construct title for Open Graph"""
+    return _("Book List: %(name)s") % {"name": book_list.name}
+
+
+@register.filter(name="opengraph_description")
+def get_opengraph_description(book_list: models.List) -> str:
+    """Construct description for Open Graph"""
+    num_books = book_list.books.all().count()
+    num_books_str = ngettext(
+        "%(num)d book - by %(user)s", "%(num)d books - by %(user)s", num_books
+    ) % {"num": num_books, "user": book_list.user}
+
+    return f"{book_list.description} {num_books_str}"


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Hardcoded language ISO in instance info
This line of code 

https://github.com/bookwyrm-social/bookwyrm/blob/290b74039297349693f4f139fa58659a19d1e1ac/bookwyrm/views/wellknown.py#L113

needs to be changed that the actual language of the instance is shown. My instance is set to German but it tells the world that it is in English.

The problem I have here (and why I just not solved it right now) is that the language is represented by a ISO 639-1 two-letter code and I do not see that we have it here. The question is: Do we need 4 letter codes in `.env`/`settings.py`or can we somehow derive from this setting and get the two letter code? 

Anyhow, I am too confused to do it atm.


Discussion:

Resolving patch:
diff --git a/bookwyrm/views/wellknown.py b/bookwyrm/views/wellknown.py
--- a/bookwyrm/views/wellknown.py
+++ b/bookwyrm/views/wellknown.py
@@ -9,7 +9,7 @@
 from django.views.decorators.http import require_GET
 
 from bookwyrm import models
-from bookwyrm.settings import DOMAIN, VERSION
+from bookwyrm.settings import DOMAIN, VERSION, LANGUAGE_CODE
 
 
 @require_GET
@@ -110,7 +110,7 @@ def instance_info(_):
                 "status_count": status_count,
             },
             "thumbnail": logo,
-            "languages": ["en"],
+            "languages": [LANGUAGE_CODE[:2]],
             "registrations": site.allow_registration,
             "approval_required": not site.allow_registration
             and site.allow_invite_requests,


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Malformed Links in Profiles and Posts
**Describe the bug**
When you write a URL at the end of a sentence in your profile or in a post, the trailing dot (.) is appended to the generated HTML anchor.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to your profile
2. Click on 'edit profile'
3. Insert "https://github.com/bookwyrm-social/bookwyrm/issues." (with the dot at the end)
4. Click on "save"
5. Follow the Link

**Example**
https://bookwyrm.social/user/taarion

**Expected behavior**
The Link shoud be without the dot

**Instance**
bookwyrm.social i.E.


---

**Desktop (please complete the following information):**
    - OS: Windows 11
    - Browser Vivaldi
    - Version 6.1




Discussion:

Resolving patch:
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py
--- a/bookwyrm/views/status.py
+++ b/bookwyrm/views/status.py
@@ -305,6 +305,11 @@ def format_links(content):
             formatted_content += potential_link[0]
             potential_link = potential_link[1:-1]
 
+        ends_with_punctuation = _ends_with_punctuation(potential_link)
+        if ends_with_punctuation:
+            punctuation_glyph = potential_link[-1]
+            potential_link = potential_link[0:-1]
+
         try:
             # raises an error on anything that's not a valid link
             validator(potential_link)
@@ -324,6 +329,9 @@ def format_links(content):
         if wrapped:
             formatted_content += wrapper_close
 
+        if ends_with_punctuation:
+            formatted_content += punctuation_glyph
+
     return formatted_content
 
 
@@ -336,6 +344,15 @@ def _wrapped(text):
     return False
 
 
+def _ends_with_punctuation(text):
+    """check if a line of text ends with a punctuation glyph"""
+    glyphs = [".", ",", ";", ":", "!", "?", "”", "’", '"', "»"]
+    for glyph in glyphs:
+        if text[-1] == glyph:
+            return True
+    return False
+
+
 def to_markdown(content):
     """catch links and convert to markdown"""
     content = format_links(content)


Test patch:
diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py
--- a/bookwyrm/tests/views/test_status.py
+++ b/bookwyrm/tests/views/test_status.py
@@ -428,6 +428,14 @@ def test_format_links_parens(self, *_):
             f'(<a href="{url}">www.fish.com/</a>)',
         )
 
+    def test_format_links_punctuation(self, *_):
+        """don’t take trailing punctuation into account pls"""
+        url = "http://www.fish.com/"
+        self.assertEqual(
+            views.status.format_links(f"{url}."),
+            f'<a href="{url}">www.fish.com/</a>.',
+        )
+
     def test_format_links_special_chars(self, *_):
         """find and format urls into a tags"""
         url = "https://archive.org/details/dli.granth.72113/page/n25/mode/2up"
Repository: bookwyrm-social/bookwyrm

Issue:
 Celery queue names inconsistent
**Is your feature request related to a problem? Please describe.**
In the admin interface, the Celery Status tab shows all the current queues.
They seemed to be only ever-increasing recently, so I had to look into why that happened.
After a lot of wasting of time, I figured out how to properly get into Flower, (and how to start it...)
Here, I discovered that the Celery worker was ignoring all but four of the queues, so I had to manually add them.
This did not really seem to be a problem. However, when I entered `broadcasts`, as that is what the queue is named in the admin interface, nothing happened. An investigation later I found out that the queue was actually called `broadcast`, singular.

**Describe the solution you'd like**
So, please fix that. Either change the name of the queue, or change it in the admin interface, so that someone can look at the admin interface to know what the queue names are...

**Describe alternatives you've considered**
N/A

**Additional context**
N/A



Discussion:

Resolving patch:
diff --git a/bookwyrm/views/admin/celery_status.py b/bookwyrm/views/admin/celery_status.py
--- a/bookwyrm/views/admin/celery_status.py
+++ b/bookwyrm/views/admin/celery_status.py
@@ -110,20 +110,20 @@ class ClearCeleryForm(forms.Form):
     queues = forms.MultipleChoiceField(
         label="Queues",
         choices=[
-            (LOW, "Low prioirty"),
+            (LOW, "Low priority"),
             (MEDIUM, "Medium priority"),
             (HIGH, "High priority"),
-            (STREAMS, "Streams"),
-            (IMAGES, "Images"),
-            (SUGGESTED_USERS, "Suggested users"),
-            (EMAIL, "Email"),
+            (BROADCAST, "Broadcast"),
             (CONNECTORS, "Connectors"),
-            (LISTS, "Lists"),
-            (INBOX, "Inbox"),
+            (EMAIL, "Email"),
+            (IMAGES, "Images"),
             (IMPORTS, "Imports"),
             (IMPORT_TRIGGERED, "Import triggered"),
-            (BROADCAST, "Broadcasts"),
+            (INBOX, "Inbox"),
+            (LISTS, "Lists"),
             (MISC, "Misc"),
+            (STREAMS, "Streams"),
+            (SUGGESTED_USERS, "Suggested users"),
         ],
         widget=forms.CheckboxSelectMultiple,
     )


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Saved lists pagination is broken
**Describe the bug**
Trying to move through pages of saved lists is broken. Instead, one moves back to all lists.

**To Reproduce**
Steps to reproduce the behavior:
1. Save enough lists to have at least two pages
2. Go to [`Lists -> Saved Lists`](https://bookwyrm.social/list/saved)
3. Click on `Next`
4. Wonder why the lists shown are not the ones you saved
5. Realize you're back on `All Lists`

**Expected behavior**
One should be able to paginate through saved lists

**Instance**
[bookwyrm.social](https://bookwyrm.social/)

**Additional comments**
I'm trying to dig through the code a bit, but I don't have time to setup dev environment and populate local dbs and whatever needs to be done. It might just be that `path` needs to be changed to `/list/saved` [here](https://github.com/bookwyrm-social/bookwyrm/blob/6667178703b93d0d1874f1fd547e97c12a2ec144/bookwyrm/views/list/lists.py#L62)? But idk, this isn't a stack I'm very intimate with 🤷



Discussion:

Resolving patch:
diff --git a/bookwyrm/views/list/lists.py b/bookwyrm/views/list/lists.py
--- a/bookwyrm/views/list/lists.py
+++ b/bookwyrm/views/list/lists.py
@@ -59,7 +59,7 @@ def get(self, request):
         data = {
             "lists": paginated.get_page(request.GET.get("page")),
             "list_form": forms.ListForm(),
-            "path": "/list",
+            "path": "/list/saved",
         }
         return TemplateResponse(request, "lists/lists.html", data)
 


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Switching editions changes "shelved" date
**Describe the bug**
When switching editions of a book already on your "To Read" list, the "shelved" date is changed to today's date.

**To Reproduce**
Steps to reproduce the behavior:
1. Pick any book on your "To read" list with more than one edition
2. Pick another edition and switch to this
3. Observe that the book's shelved date is now today

**Expected behavior**
This shouldn't changed the shelved date

**Instance**
https://books.theunseen.city

---

**Desktop (please complete the following information):**
    - OS: MacOS 14.1
    - Browser: Firefox
    - Version: 20.0 (64-bit)



Discussion:

Resolving patch:
diff --git a/bookwyrm/views/books/editions.py b/bookwyrm/views/books/editions.py
--- a/bookwyrm/views/books/editions.py
+++ b/bookwyrm/views/books/editions.py
@@ -93,6 +93,7 @@ def switch_edition(request):
                 user=shelfbook.user,
                 shelf=shelfbook.shelf,
                 book=new_edition,
+                shelved_date=shelfbook.shelved_date,
             )
             shelfbook.delete()
 


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
"year in the books" should not appear for newly registered users
**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
1. Register a new account during the time "{year} in the books" appears
2. Get a messsage encouraging you to see all the books you read in the year, which will be none.

**Expected behavior**
This should not be displayed for users who have no readthroughs.

**Screenshots**

![Screenshot 2024-01-03 at 11 08 20 am](https://github.com/bookwyrm-social/bookwyrm/assets/17669239/a33d5f2e-a666-4e57-93c3-59a28a62bddd)

**Instance**
dev site




Discussion:
Hi @hughrun, can I work on this? 
Please do @rsk2! I should note that I _think_ it's a "good first issue" as the logic should be pretty simple to filter this out of the template. But I haven't had a close look at the relevant code so shout out if you need any help.

Resolving patch:
diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py
--- a/bookwyrm/views/feed.py
+++ b/bookwyrm/views/feed.py
@@ -1,4 +1,5 @@
 """ non-interactive pages """
+from datetime import date
 from django.contrib.auth.decorators import login_required
 from django.core.paginator import Paginator
 from django.db.models import Q
@@ -52,6 +53,19 @@ def get(self, request, tab, filters_applied=False):
 
         suggestions = suggested_users.get_suggestions(request.user)
 
+        cutoff = (
+            date(get_annual_summary_year(), 12, 31)
+            if get_annual_summary_year()
+            else None
+        )
+        readthroughs = (
+            models.ReadThrough.objects.filter(
+                user=request.user, finish_date__lte=cutoff
+            )
+            if get_annual_summary_year()
+            else []
+        )
+
         data = {
             **feed_page_data(request.user),
             **{
@@ -66,6 +80,7 @@ def get(self, request, tab, filters_applied=False):
                 "path": f"/{tab['key']}",
                 "annual_summary_year": get_annual_summary_year(),
                 "has_tour": True,
+                "has_summary_read_throughs": len(readthroughs),
             },
         }
         return TemplateResponse(request, "feed/feed.html", data)


Test patch:
Repository: bookwyrm-social/bookwyrm

Issue:
Flower crash : ValueError: Couldn't import 'celerywyrm': Environment variable "DATA_UPLOAD_MAX_MEMORY_SIZE" invalid: Not a valid integer.`
Since updating my .env (following the .env.example) the flower application no longer worked.
Here's a bit of the error :

`master celery[2501464]: ValueError: Couldn't import 'celerywyrm': Environment variable "DATA_UPLOAD_MAX_MEMORY_SIZE" invalid: Not a valid integer.`

I changed :
DATA_UPLOAD_MAX_MEMORY_SIZE = (1024**2 * 100)
to
DATA_UPLOAD_MAX_MEMORY_SIZE = 204800

and it seems to work again


Discussion:
@prolibre are you able to check whether this works if the value is `DATA_UPLOAD_MAX_MEMORY_SIZE=(1024**2 * 100)` (i.e. no spaces around the equals sign)?
hmm don't worry I answered my own question (no).

Resolving patch:
diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py
--- a/bookwyrm/settings.py
+++ b/bookwyrm/settings.py
@@ -446,4 +446,6 @@
 # user with the same username - in which case you should change it!
 INSTANCE_ACTOR_USERNAME = "bookwyrm.instance.actor"
 
-DATA_UPLOAD_MAX_MEMORY_SIZE = env.int("DATA_UPLOAD_MAX_MEMORY_SIZE", (1024**2 * 100))
+# We only allow specifying DATA_UPLOAD_MAX_MEMORY_SIZE in MiB from .env
+# (note the difference in variable names).
+DATA_UPLOAD_MAX_MEMORY_SIZE = env.int("DATA_UPLOAD_MAX_MEMORY_MiB", 100) << 20
diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py
--- a/bookwyrm/templatetags/utilities.py
+++ b/bookwyrm/templatetags/utilities.py
@@ -126,7 +126,7 @@ def id_to_username(user_id):
         value = f"{name}@{domain}"
 
         return value
-    return "a new user account"
+    return _("a new user account")
 
 
 @register.filter(name="get_file_size")


Test patch:
Repository: emissary-ingress/emissary

Issue:
Users need statsd support
Ambassador needs to be able to send stats off to statsd, whatever statsd the user wants to use.


Discussion:

Resolving patch:
diff --git a/ambassador/VERSION.py b/ambassador/VERSION.py
--- a/ambassador/VERSION.py
+++ b/ambassador/VERSION.py
@@ -1,2 +1,2 @@
 # Don't change this line without also changing .bumpversion.cfg
-Version = "0.5.0"
+Version = "0.5.1"


Test patch:
Repository: emissary-ingress/emissary

Issue:
Users can use TLS client-cert authentication
Envoy already supports this.

DoD:
- users can enable the TLS-cert auth filter
- users have some way to configure valid principals



Discussion:

Resolving patch:
diff --git a/ambassador/ambassador.py b/ambassador/ambassador.py
--- a/ambassador/ambassador.py
+++ b/ambassador/ambassador.py
@@ -446,7 +446,8 @@ def main():
     # Set up the TLS config stuff.
     app.envoy_tls_config = TLSConfig(
         "AMBASSADOR_CHAIN_PATH", "/etc/certs/fullchain.pem",
-        "AMBASSADOR_PRIVKEY_PATH", "/etc/certs/privkey.pem"
+        "AMBASSADOR_PRIVKEY_PATH", "/etc/certs/privkey.pem",
+        "AMBASSADOR_CACERT_PATH", "/etc/cacert/fullchain.pem"
     )
 
     app.stats = EnvoyStats()
diff --git a/ambassador/envoy.py b/ambassador/envoy.py
--- a/ambassador/envoy.py
+++ b/ambassador/envoy.py
@@ -18,9 +18,11 @@ def percentage(x, y):
 
 
 class TLSConfig (object):
-    def __init__(self, chain_env, chain_default_path, privkey_env, privkey_default_path):
+    def __init__(self, chain_env, chain_default_path, privkey_env, privkey_default_path,
+                       cacert_chain_env, cacert_chain_default_path):
         self.chain_path = os.environ.get(chain_env, chain_default_path)
         self.privkey_path = os.environ.get(privkey_env, privkey_default_path)
+        self.cacert_chain_path = os.environ.get(cacert_chain_env, cacert_chain_default_path)
 
     def check_file(self, path):
         found = False
@@ -34,15 +36,30 @@ def check_file(self, path):
         return found
 
     def config_block(self):
+        config = {}
+
         if (self.check_file(self.chain_path) and
             self.check_file(self.privkey_path)):
+            config["cert_chain_file"] = self.chain_path
+            config["private_key_file"] = self.privkey_path
+
+        if self.check_file(self.cacert_chain_path):
+            config["ca_cert_file"] = self.cacert_chain_path
+
+        return config
+
+    def cacert_config_block(self):
+        if self.check_file(self.cacert_chain_path):
             return {
-                "cert_chain_file": self.chain_path,
-                "private_key_file": self.privkey_path
+              "type": "read",
+              "name": "client_ssl_auth",
+              "config": {
+                "auth_api_cluster": "ambassador_cluster",
+                "stat_prefix": "main_tls_auth"
+              }
             }
         else:
-            return {}
-
+            return None
 
 class EnvoyConfig (object):
     route_template = '''
@@ -268,6 +285,11 @@ def write_config(self, path):
                 "tcp://0.0.0.0:443"
             )
 
+            client_cert_config = self.tls_config.cacert_config_block()
+
+            if client_cert_config:
+                dpath.util.get(config, "/listeners/1/filters").append(client_cert_config)
+
         output_file = open(path, "w")
 
         json.dump(config, output_file, 


Test patch: