U4-11528 - Problem with length of culture in database

Created by Rafa Gimeno 19 Jul 2018, 07:10:06 Updated by Sebastiaan Janssen 25 Jul 2018, 08:04:34

Tags: Up For Grabs PR


There's a problem with the culture "Valencian (Spain) [ca-ES-valencia]". The length of its languageISOCode is 14 characters (ca-ES-valencia) and the maximum length available in database is 10 (nvarchar(10)). I think this is an error because this culture is allowed in the language selection of the Umbraco backoffice and this culture is supported here: https://msdn.microsoft.com/en-us/library/hh441729.aspx



Sebastiaan Janssen 19 Jul 2018, 08:50:54

Ah, well that's annoying! For now you can of course change your database.

I've marked as "Up for grabs" so that you or someone else coming along could create a pull request for it.

Rafa Gimeno 19 Jul 2018, 10:23:01

@sebastiaan Thanks a lot! I've already changed it in my database design, but it would be interesting having this by default in order to update Umbraco version without problems.

Nathan Skidmore 23 Jul 2018, 16:50:33

@sebastiaan I was looking at picking this up but I can't see how the database is generated/updated during an install. I was expecting to see SQL statements in the code but I can't find them. Can you point me in the right direction? Cheers

Sebastiaan Janssen 23 Jul 2018, 18:54:08

@skidmow Sure!

So the database creation happens in the [DatabaseSchemaCreation|https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs] class. This will lead you to the [LanguageDto|https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Core/Models/Rdbms/LanguageDto.cs] class which has a Length attribute on the IsoCode property which should be changed to something larger (you'll need to figure out which is the longest culture name).

You'll also need to create a migration that will help people that are upgrading to a newer version, they will already have an existing database so they will require an update. An example of a migration is [ReduceLoginNameColumnsSize|https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSixZero/ReduceLoginNameColumnsSize.cs]. Of course this one reduces instead of increases the column size, so of course you'd do the opposite for this issue.

Nathan Skidmore 24 Jul 2018, 09:48:38

@sebastiaan thanks for the info! I'll take a look.

Nathan Skidmore 24 Jul 2018, 10:18:32

The longest culture name is indeed 14, as confirmed by the code below:

public static void Main(string[] args) { var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); string longestCulture = ""; int longestCultureLength = 0;

        foreach (var culture in cultures)
            if (culture.Name.Length > longestCultureLength)
                longestCultureLength = culture.Name.Length;
                longestCulture = culture.Name;

        Console.WriteLine("Longest Culture: " + longestCulture);
        Console.WriteLine("Longest Culture Length: " + longestCultureLength);

Nathan Skidmore 24 Jul 2018, 16:24:49

Created Pull Request: https://github.com/umbraco/Umbraco-CMS/pull/2791

Priority: Minor

Type: Bug

State: Fixed


Difficulty: Easy

Category: Localization

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.9.2

Due in version: 7.12.0


Story Points: