# PG::StringDataRightTruncation (FEHLER: Wert zu lang für Typ character varying(500))

**URL:** https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426
**Category:** Bug
**Created:** [7. März 2021 um 21:40 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426 "2021-03-07T21:40:27Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [7. März 2021 um 21:40 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/1 "2021-03-07T21:40:27Z")

</div>

Wenn ich versuche, den ersten Beitrag in [diesem Thema](https://rembetiko.gr/t/%CE%B2%CF%81%CE%AE%CE%BA%CE%B1-%CE%BA%CE%AC%CF%84%CE%B9-%CE%B3%CE%B9%CE%B1-%CE%BC%CE%AD%CE%BD%CE%B1-%CF%84%CE%BF-%CF%81%CE%B5%CE%BC%CF%80%CE%AD%CF%84%CE%B9%CE%BA%CE%BF-%CF%84%CF%81%CE%B1%CE%B3%CE%BF%CF%8D%CE%B4%CE%B9-%CE%B5%CE%AF%CE%BD%CE%B1%CE%B9-%CE%BA%CE%B1%CF%84%CE%AC-%CE%B2%CE%AC%CF%83%CE%B9%CE%BD-%CE%B1%CF%81%CE%BC%CE%BF%CE%BD%CE%B9%CE%BA%CE%BF-%CE%BA%CE%B1%CE%B9-%CE%B4%CE%B9%CE%AC-%CF%84%CE%BF%CF%8D%CF%84%CE%BF-%CF%80%CE%BF%CE%BB%CF%85%CF%86%CF%89%CE%BD%CE%B9%CE%BA%CE%BF/42000) zu bearbeiten, erhalte ich einen HTTP-500-Fehlercode. Die Fehlerprotokolle melden folgenden fatalen Fehler:

```plaintext
Message (7 copies reported)

PG::StringDataRightTruncation (ERROR: value too long for type character varying(500)
)
app/models/topic_link.rb:240:in `safe_create_topic_link'
app/models/topic_link.rb:334:in `ensure_entry_for'
app/models/topic_link.rb:128:in `block (2 levels) in extract_from'
app/models/topic_link.rb:126:in `block in extract_from'
app/models/topic_link.rb:124:in `each'
app/models/topic_link.rb:124:in `extract_from'
lib/post_revisor.rb:224:in `revise!'
app/controllers/topics_controller.rb:379:in `update'
app/controllers/application_controller.rb:358:in `block in with_resolved_locale'
app/controllers/application_controller.rb:358:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:68:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:355:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:23:in `call'
lib/middleware/request_tracker.rb:177:in `call'

Backtrace

rack-mini-profiler (2.3.1) lib/patches/db/pg.rb:113:in `exec'
rack-mini-profiler (2.3.1) lib/patches/db/pg.rb:113:in `async_exec'
mini_sql (1.0.1) lib/mini_sql/postgres/connection.rb:201:in `run'
mini_sql (1.0.1) lib/mini_sql/postgres/connection.rb:56:in `query_single'
app/models/topic_link.rb:240:in `safe_create_topic_link'
app/models/topic_link.rb:334:in `ensure_entry_for'
app/models/topic_link.rb:128:in `block (2 levels) in extract_from'
activerecord (6.0.3.3) lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `block in transaction'
activerecord (6.0.3.3) lib/active_record/connection_adapters/abstract/transaction.rb:280:in `block in within_new_transaction'
activesupport (6.0.3.3) lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'

Env

HTTP HOSTS: rembetiko.gr

```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [8. März 2021 um 04:31 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/2 "2021-03-08T04:31:59Z")

</div>

Sieht so aus, als ob es mit der URL zu tun hat – sie ist länger als 500 Zeichen.

Wir sollten sie definitiv kürzen und eventuell überspringen, statt einen 500er-Fehler zu verursachen.

Wie lang ist die längste URL im Beitrag?

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [8. März 2021 um 09:27 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/3 "2021-03-08T09:27:29Z")

</div>

Danke @sam,

die einzige URL, die der Beitrag hat, stammt aus einem Zitat. Die URL lautet:

`https://rembetiko.gr/t/%CE%BC%CE%B1%CE%BA%CE%AC%CE%BC-%CE%B2%CF%85%CE%B6%CE%B1%CE%BD%CF%84%CE%B9%CE%BD%CE%BF%CE%AF-%CE%B4%CF%81%CF%8C%CE%BC%CE%BF%CE%B9/6034/30`

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [8. März 2021 um 09:33 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/4 "2021-03-08T09:33:22Z")

</div>

Das sind nur 159 Zeichen … mal sehen, was hier passiert:

> **[Μακάμ - Βυζαντινοί Δρόμοι](https://rembetiko.gr/t/%CE%BC%CE%B1%CE%BA%CE%AC%CE%BC-%CE%B2%CF%85%CE%B6%CE%B1%CE%BD%CF%84%CE%B9%CE%BD%CE%BF%CE%AF-%CE%B4%CF%81%CF%8C%CE%BC%CE%BF%CE%B9/6034/30)**
>
> Γιάννη, εκτός από τις ευχές μπου γιά Καλό Πάσχα, θέλω να πω πως πίστευα ότι το θέμα έχει λυθεί προ καιρού. Όχι μόνο από τα πρίμα-σεγκόντα και πέρα, αλλά ακόμα και στην Πειραιώτικη κομπανία, αλλά και σ΄ένα σεβαστό μέρος της Σμυρνέϊκης του Πειραιά...

[Μακάμ - Βυζαντινοί Δρόμοι - #30 από kwstas\_ferris - Παραδοσιακή μουσική - Ρεμπέτικο Φόρουμ](https://rembetiko.gr/t/%CE%BC%CE%B1%CE%BA%CE%AC%CE%BC-%CE%B2%CF%85%CE%B6%CE%B1%CE%BD%CF%84%CE%B9%CE%BD%CE%BF%CE%AF-%CE%B4%CF%81%CF%8C%CE%BC%CE%BF%CE%B9/6034/30)

So komisch … damit kann ich den Fehler nicht nachstellen.

Vielleicht hat es damit zu tun, dass es der erste Beitrag ist?

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [8. März 2021 um 09:58 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/5 "2021-03-08T09:58:41Z")

</div>

Das hat mit dem Titel des Themas zu tun. Als ich den Titel des Themas auf etwas Kürzeres geändert habe, hörten die Fehler auf. Als ich versuchte, ihn auf seine ursprüngliche Länge zurückzusetzen, trat beim Aktualisieren des Titels ein 500-Fehler auf. Nach dem 500-Fehler habe ich die Seite neu geladen, und der Titel wurde aktualisiert.

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [8. März 2021 um 13:21 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/6 "2021-03-08T13:21:42Z")

</div>

**Ich habe das etwas genauer untersucht:**

Dies tritt beim Aktualisieren des „verlinkten

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [8. März 2021 um 22:43 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/7 "2021-03-08T22:43:27Z")

</div>

@Osama, könntest du zu deiner Liste hinzufügen, eine verzeihlichere Kürzung im Kern zu untersuchen? Idealerweise kannst du das in einem Testfall reproduzieren.

Sicherlich nicht dringend, wenn du Zeit hast.

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [1. April 2021 um 20:23 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/8 "2021-04-01T20:23:38Z")

</div>

Entschuldige die Störung, aber wurde dieser Fehler bereits behoben? Heute ist mir auf unserem Forum ein zweiter Fall davon begegnet…

Danke für eure harte Arbeit! 😃

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [6. April 2021 um 02:52 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/9 "2021-04-06T02:52:09Z")

</div>

Wir sind leider etwas beschäftigt. Es steht auf @Osamas Liste, und wir hoffen, dass wir es in den nächsten vier Wochen irgendwann schaffen.

---

<div class="post-metadata">

### Author: ![andrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrei/32/205142_2.png) [@andrei](https://meta.discourse.org/u/andrei)
#### Post date: [2. Juni 2021 um 11:32 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/14 "2021-06-02T11:32:36Z")

</div>

@chrispanag das Problem ist jetzt gelöst:

> <https://github.com/discourse/discourse/pull/13134>
>
> Users who use encoded slugs on their sites sometimes \[run into 500 error\](https:…//meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426) when pasting a link to another topic in a post. The problem happens when generating a backward "reflection" link that would appear in a linked topic:
> \<img width="400" alt="Screenshot 2021-05-25 at 16 11 53" src="https://user-images.githubusercontent.com/1274517/119496067-29330e80-bd74-11eb-8883-87d71108b4e0.png"\>
> 
> Link URL restricted on the database level to 500 chars in length. At first glance it should work since we have a restriction on topic title length:
> \<img width="450" alt="Screenshot 2021-05-24 at 17 56 24" src="https://user-images.githubusercontent.com/1274517/119494745-b2494600-bd72-11eb-8bdc-a3e70c62fdf4.png"\>
> 
> But it doesn't work when a site uses encoded slugs, like \[here\](https://rembetiko.gr/t/%CE%B2%CF%81%CE%AE%CE%BA%CE%B1-%CE%BA%CE%AC%CF%84%CE%B9-%CE%B3%CE%B9%CE%B1-%CE%BC%CE%AD%CE%BD%CE%B1-%CF%84%CE%BF-%CF%81%CE%B5%CE%BC%CF%80%CE%AD%CF%84%CE%B9%CE%BA%CE%BF-%CF%84%CF%81%CE%B1%CE%B3%CE%BF%CF%8D%CE%B4%CE%B9-%CE%B5%CE%AF%CE%BD%CE%B1%CE%B9-%CE%BA%CE%B1%CF%84%CE%AC-%CE%B2%CE%AC%CF%83%CE%B9%CE%BD-%CE%B1%CF%81%CE%BC%CE%BF%CE%BD%CE%B9%CE%BA%CE%BF-%CE%BA%CE%B1%CE%B9-%CE%B4%CE%B9%CE%AC-%CF%84%CE%BF%CF%8D%CF%84%CE%BF-%CF%80%CE%BF%CE%BB%CF%85%CF%86%CF%89%CE%BD%CE%B9%CE%BA%CE%BF/42000) (take a look at the URL). The link to a topic, in this case, can be much longer than 500 characters.
> 
> By the way, an error happens only when generating a "reflection" link and doesn't happen with a direct link, we \[truncate that link\](https://github.com/discourse/discourse/blob/6e2ecf40c7456a1af7f6470d09921f0138fbd4bb/app/models/topic\_link.rb#L309). It works because, in this case, the original long link is still present in the post body and can be used for navigation. But we can't do the same for backward "reflection" links (without rewriting their implementation), the whole link must be saved to the database.
> 
> The simplest and cleanest solution will be just to remove the restriction on the database level. Abuse is impossible here since we are already protected by the restriction on topic title length. There aren’t performance benefits in using length-constrained columns in Postgres, in fact, length-constrained columns need a few extra CPU cycles to check the length when storing data (\[doc\](https://www.postgresql.org/docs/9.3/datatype-character.html)).

Wie du sagtest, trat der Fehler auf, wenn ein Rückwärtslink vom verlinkten Beitrag zum Originalbeitrag erstellt wurde und der Originalbeitrag einen langen Titel hatte.

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [4. Juni 2021 um 13:32 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/15 "2021-06-04T13:32:23Z")

</div>

Vielen Dank für deine Lösung! 😃

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [5. Juni 2021 um 08:00 UTC](https://meta.discourse.org/t/pg-stringdatarighttruncation-error-value-too-long-for-type-character-varying-500/182426/16 "2021-06-05T08:00:01Z")

</div>

Dieses Thema wurde automatisch nach 2 Tagen geschlossen. Neue Antworten sind nicht mehr erlaubt.
