Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UrlField.max_length is too short

See original GitHub issue

Wagtail is using the UrlField provided by Django, which has max_length=200. Sometimes this is not enough, especially for certain embeds.

Could we use a value larger than that for maybe all UrlFields in Wagtail? Or what would be the best way to override this on a specific website?

Related to this, someone managed to submit a page with a long url without any validation errors, which then failed when publishing it. But the draft did get saved (along with the long url) but the page editor form didn’t render at all (because of an error when rendering the url field and TEMPLATE_DEBUG=False). Changing the embed url field length directly in the database fixed this. Although this was an older version of Wagtail, so I’ll give it a try on 1.2 with richtext embeds and streamfield embed blocks too.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

GTpyrocommented, Oct 16, 2020

Instagram embed doesn’t work either, due to thumbnail_urls that are too long such as:

Seeing as this problem is caused by this bug, instead of creating a new issue, I’m just reporting it here, hope that’s alright.

I just ran into this exact problem and my google skills failed me before I opened up #6467. It’s essentially the same issue. The max_length constraint is currently preventing me from embedding instagram posts.

thibaudcolascommented, Mar 6, 2018

See also #4292:

Embedding a URL longer than 200 chars results in: DataError: value too long for type character varying(200).

Steps to Reproduce

  1. In a Wagtail project using StreamField
  2. Add ('embed', EmbedBlock()), to it
  3. Create/edit a page and add an Embed block
  4. Add an URL with more than 200 chars (for example:

From wagtail/embeds/ (url = models.URLField()) url is being created with a default max_length of 200. We should be able to safely increase this limit to max_length=255. I may still run into issues with Matomo URLs but I can’t think of a reason to not allow 255 chars. More would give me more breathing room but that can potentially cause issues with some (older) backends, MySQL < 5.0.3 comes to mind.

In my opinion there shouldn’t be any length restriction on embed URLs. I don’t see the value in having that restriction to start with, and in many cases shortening the URL to make it comply simply isn’t an option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

a Django URLField has fixed max_length as 200 characters
One thing I'd check is the database table's column definition. 200 is the default length, so if you created your database before increasing...
Read more >
URL field maxlength of 128 characters is too small - Drupal
The problem is, that the new URL field does not have maxlength attribute defined, so it uses the default of 128 characters, which...
Read more >
URLField - Django Models - GeeksforGeeks
The maximum length (in characters) of the field. The max_length is enforced at the database level and in Django's validation using ...
Read more >
Solved: Size of an URL field used in a Menu Item - ServiceNow
The URL type field hides the Max Length field on the Dictionary form by default due to a UI Policy. But there isn't...
Read more >
CharField cannot have a "max_length" greater than 255 when ...
not sure why django hits this error since the true max length is 767, not 255: ... ERROR 1071 (42000): Specified key was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found