No Code Attached Yet bug
avatar uzielweb
uzielweb
18 Jan 2024

Steps to reproduce the issue

I have a custom component with a long table file name for categories. Eg.: com_portal_transicao.transicaoregulacoes.category.271

Expected result

Save categories without errors

Actual result

I got this error message:
1062 Duplicate entry 'com_portal_transicao.transicaoregulacoes.category.' for key '#__assets.idx_asset_name'

System information (as much as possible)

PHP 8.3
Mysql 8
Joomla 3
Joomla 4
Joomla 5

Additional comments

Please provide a long VARCHAR for this column: name in the assets table.
The ideal length is 255 in both "name" and "title" columns. I suggest because this is the default Joomla Article

Thanks, for advance! I trust in the Joomla team!

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar uzielweb uzielweb - open - 18 Jan 2024
avatar joomla-cms-bot joomla-cms-bot - change - 18 Jan 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 18 Jan 2024
avatar Quy
Quy - comment - 18 Jan 2024

Duplicate #42283?

avatar Quy Quy - change - 19 Jan 2024
Labels Added: Information Required
avatar Quy Quy - labeled - 19 Jan 2024
avatar richard67 richard67 - change - 19 Jan 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-01-19 14:46:59
Closed_By richard67
avatar richard67 richard67 - close - 19 Jan 2024
avatar richard67
richard67 - comment - 19 Jan 2024

@uzielweb It seems this is a duplicate to your other issue #42283 . Please do not open again and again issues for the same thing. It does not help anything.

Closing as duplicate report.

avatar Fedik
Fedik - comment - 19 Jan 2024

It different:

However both for the same #__assets table

avatar richard67 richard67 - change - 19 Jan 2024
Status Closed New
Closed_Date 2024-01-19 14:46:59
Closed_By richard67
avatar richard67 richard67 - reopen - 19 Jan 2024
avatar Fedik Fedik - change - 19 Jan 2024
Labels Added: bug
Removed: Information Required
avatar Fedik Fedik - labeled - 19 Jan 2024
avatar Fedik Fedik - unlabeled - 19 Jan 2024
avatar richard67
richard67 - comment - 20 Jan 2024

Hmm, 100 will not be enough.

The asset names for categories are determined by the Category table class here: https://github.com/joomla/joomla-cms/blob/5.0-dev/libraries/src/Table/Category.php#L290 .

The $this->extension comes from the name column of the #__extensions table. That can have a length of max. 100.

Then ".category" is appended, so we have max. 109 characters.

Finally, ".<id>" is appended, with <id> being the category ID. That can have a length of up to 10 characters (signed or unsigned integers on MySQL or MariaDB or PostgreSQL databases).

So we need a max. length of 120 characters for the asset names of categories.

But this is only for categories.

We have other asset types like e.g. "com_modules.module.<id>" for module or "com_content.transition.1" for workflow transitions. The length of that middle part "category" or "module" or "transition" is not really limited anywhere.

We have another table #__content_types which uses type aliases which are created in a similar way, just that there is no ".<id>" appended at the end. That table's type_alias column has max. 400 characters. If we wanted to be consistent with that, we would need max. 411 characters due to the appended ".<id>".

On Joomla 4 which has to support MySQL < 5.7 and MariaDB < 10.2 the maximum key length was 767 bytes, which means for utf8mb4 max. 191 characters, so the unique key would have been limited to the first 191 characters only, so a length of asset names greater than that would not really have worked.

But on Joomla 5 we require database versions which support a max. key length of 3072 bytes, which would be max. 768 characters with utf8mb4. So a max. length of 411 would work here, but the question is if we really want it to be that big.

We could forget about that #__content_types table and say we assume that the middle part of the asset name can be max. 20 characters like it is with the type column in the extensions table. Then we would have max. 132 characters for the complete asset name.

What do others think? Opinions please.

avatar brianteeman
brianteeman - comment - 20 Jan 2024

Thanks for the analysis @richard67 I am wondering why we have never come across this before

avatar richard67
richard67 - comment - 20 Jan 2024

I am wondering why we have never come across this before

@brianteeman That can only have been lucky circumstances.

avatar Fedik
Fedik - comment - 20 Jan 2024

I can guess it was made to save memory, or speed up query, or something like that. Because this table is extensively in use.

I had this isue in past in one of my custom component, and just hacked the __asset table by install script ?

$db = Factory::getDbo();
$assetTable = $db->replacePrefix('#__assets');
$query = 'SELECT CHARACTER_MAXIMUM_LENGTH FROM information_schema.columns'
 .' WHERE table_schema = DATABASE() AND table_name = ' . $db->q($assetTable) . ' AND COLUMN_NAME = ' . $db->q('name');
$result = (int) $db->setQuery($query)->loadResult();

if ($result < 80) {
  $query = 'ALTER TABLE ' . $assetTable . ' MODIFY ' . $db->qn('name') . ' VARCHAR(80)';
  $db->setQuery($query)->execute();
}

I not sure what length is good or enough here, but could assume that the column should contain only UTF-8 latin symbols (non utf8mb4), and allow default 255.

avatar richard67
richard67 - comment - 20 Jan 2024

@Fedik If we want to fix this issue also in 4.4-dev we are limited to max. 191 characters due to the max. key size. In 5.x-dev we don't have this limitation due to the database requirements of J5. So it's the question if it's a bug fix or a new feature, and in case of bug fix if we want to fix it in 4.4, too.

Personally I tend to not fix it in 4.4-dev because it would need an update SQL for 4.4.x and another one in the 5.x-dev branches for 5.0.x to cater for all possible update scenarios.

avatar Fedik
Fedik - comment - 20 Jan 2024

To me 5.x is fine. What others will say.

avatar uzielweb uzielweb - change - 22 Jan 2024
Title
Assets table has only 50 characteres in the VARCHAR type for "name" column
Assets table has only 50 characteres in the VARCHAR type for "name" column and "100" in the "title" column
avatar uzielweb uzielweb - edited - 22 Jan 2024
avatar uzielweb uzielweb - change - 22 Jan 2024
The description was changed
avatar uzielweb uzielweb - edited - 22 Jan 2024
avatar uzielweb uzielweb - change - 22 Jan 2024
The description was changed
avatar uzielweb uzielweb - edited - 22 Jan 2024
avatar richard67
richard67 - comment - 24 Jan 2024

I will create a pull request on weekend.

avatar richard67
richard67 - comment - 27 Jan 2024

The ideal length is 255 in both "name" and "title" columns. I suggest because this is the default Joomla Article

@uzielweb As I explained in my comment above, we cannot use 255 for the "name" column as there is a unique index on it and the maximum index lengths on MySQL < 5.7 and MariaDB < 10.2 is 191 characters, and Joomla 4 still has to support these database versions. So your statement in the description about ideal length is not right.

avatar uzielweb
uzielweb - comment - 6 Jun 2024

All right, but we need this in Joomla 5, MYSQL 8, as ideal.
Sorry for my late comment about this.

Add a Comment

Login with GitHub to post a comment