Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fails to work on string ids such as UUID #28

Open
doncadavona opened this issue Feb 14, 2025 · 4 comments
Open

[Bug] Fails to work on string ids such as UUID #28

doncadavona opened this issue Feb 14, 2025 · 4 comments
Assignees

Comments

@doncadavona
Copy link

doncadavona commented Feb 14, 2025

Bug report

What I did

Implemented Revice on My UserCrudController

What I expected to happen

I should be able to edit a user entry.

What happened

When I save the user entry, this error occurs:

Illuminate\Database\QueryException

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'user_id' at row 1

Image

What I've already tried to fix it

I have only gone through reading issues in https://github.com/VentureCraft/revisionable, which seem to be inactive.

This particular issue discusses the issue, but is unresponded to by the developers:

VentureCraft/revisionable#191

I have seen that https://github.com/joshbrw/revisionable-uuid resolves the issue.

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

### PHP VERSION:
8.3.16

### PHP EXTENSIONS:
Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, random, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, bcmath, bz2, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, iconv, igbinary, imagick, exif, mysqli, pdo_mysql, pdo_sqlite, Phar, posix, readline, shmop, SimpleXML, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, xmlreader, xmlwriter, xsl, zip, redis, Zend OPcache

### LARAVEL VERSION:
10.48.28.0

### BACKPACK PACKAGE VERSIONS:
backpack/activity-log: 2.0.6
backpack/backupmanager: v5.0.5
backpack/basset: 1.3.6
backpack/crud: 6.7.51
backpack/generators: v4.0.7
backpack/logmanager: v5.0.2
backpack/medialibrary-uploaders: 1.2.1
backpack/permissionmanager: 7.2.1
backpack/pro: 2.2.32
backpack/revise-operation: 2.0.0
backpack/theme-tabler: 1.2.17
Copy link

welcome bot commented Feb 14, 2025

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

  • Bug Reports, Feature Requests - Github Issues (here);
  • Quick help (How do I do X) - Gitter Chatroom;
  • Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the backpack-for-laravel tag;
  • Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

Copy link

Based on the information provided in your question and the knowledge sources available, it appears that you're experiencing an issue with Backpack CRUD when using UUID as the primary key for your User model. This problem is related to how Backpack handles non-integer primary keys, particularly UUIDs.

The error you're encountering suggests that there's a mismatch between the expected data type for the user_id column and the actual data being saved. This is likely because Backpack is trying to save a string UUID into a column that's expecting an integer.

To resolve this issue, you need to make sure that Backpack correctly handles UUID primary keys. Here are a few steps you can try:

  1. Ensure that your User model is properly configured to use UUID as the primary key. Add the following to your User model:
protected $keyType = 'string';
public $incrementing = false;
  1. Make sure your database migration for the users table is set up to use UUID:
$table->uuid('id')->primary();
  1. If you're using the Revise operation, make sure it's compatible with UUID primary keys. The Revise operation might need additional configuration to work correctly with non-integer primary keys.

  2. Check your UserCrudController to ensure that it's properly set up to handle UUID primary keys. You might need to override some methods to explicitly handle the UUID.

Unfortunately, the knowledge sources don't provide a specific solution for this exact issue with the Revise operation and UUID primary keys. However, there are some related issues that have been addressed in the past:

  1. Github Issue: UUIDs Strings not working with Checkbox Form field - This issue discusses problems with UUIDs in Backpack, although it's not directly related to the Revise operation.

  2. Github Issue: Support for UUID - This older issue discusses UUID support in Backpack, which might provide some context.

If these steps don't resolve your issue, you may need to dig deeper into how the Revise operation is interacting with your User model and possibly customize it to handle UUID primary keys correctly. Consider opening a new issue on the Backpack GitHub repository with your specific implementation details, as this might be a bug that needs to be addressed by the Backpack team.

ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️

Relevant sources:

Github Issue (closed): [Bug]
Github Issue (closed): Support for UUID
Github Issue (closed): [Bug] Cannot update data model after 4.1.44 update
Github Issue (closed): [Bug] Edit about now broken after automatic "required fields"
Bug report
Github Issue (closed): [4.0.9] [BUG] select2_multiple breaks with UUID
Github Issue (closed): [Bug] Editable columns update error
Github Issue (closed): [Bug] Update of entity can not be saved in tests with error "No query results for model [App\Models\User]"
Github Issue (closed): [4.1][Feature] Use getRouteKey() instead of getKey() to allow for UUIDs that are not primary keys
Github Issue (closed): [Bug] Edit function on uniqe field
Github Issue (closed): [Bug] UUIDs Strings not working with Checkbox Form field
Github Issue (closed): [Bug] Getting Error on Create / Edit User
Github Issue (closed): [Bug] Reorder not working with uuid primary

@karandatwani92
Copy link

Hey @doncadavona

Your efforts show you already know the issue is in the revisional package.
Now, you are overriding a few things to accommodate the UUID support, and everyone can customize it in various ways at their level.

Can you explain what change exactly you are looking for in the backpack?

@doncadavona
Copy link
Author

doncadavona commented Feb 18, 2025

Hi @karandatwani92 , I managed to solve the issue by publishing the database migration class (database/migrations/2013_04_09_062329_create_revisions_table.php) of the https://github.com/VentureCraft/revisionable package, then editing the following table column declarations to:

$table->uuid('revisionable_id');
$table->uuid('user_id')->nullable();

from:

$table->unsignedBigInteger('revisionable_id');
$table->unsignedBigInteger('user_id')->nullable();

What I was looking for exactly was a way to implement UUID/ULID with minimal effort as much as possible, where I don't have to touch other packages' files, especially for this common use case (I believe).

I am also thinking we may be able to document this common use case for UUID/ULID, say for example let's add in the following note in the docs (https://backpackforlaravel.com/docs/6.x/crud-operation-revisions):

NOTICE When using UUID or ULID primary keys for your models, make sure that the revisions table uses the appropriate UUID or ULID columns. To do that, publish the database migration file, php artisan vendor:publish --provider="Venturecraft\Revisionable\RevisionableServiceProvider" then edit the migration file (database/migrations/2013_04_09_062329_create_revisions_table.php) like so:

Schema::create('revisions', function ($table) {
    $table->bigIncrements('id');
    $table->string('revisionable_type');

    // Original
    //$table->unsignedBigInteger('revisionable_id');
    //$table->unsignedBigInteger('user_id')->nullable();

    // When using UUID
    $table->uuid('revisionable_id');
    $table->uuid('user_id')->nullable();

    // When using ULID
    //$table->ulid('revisionable_id');
    //$table->ulid('user_id')->nullable();

    $table->string('key');
    $table->text('old_value')->nullable();
    $table->text('new_value')->nullable();
    $table->timestamps();

    $table->index(['revisionable_id', 'revisionable_type']);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

3 participants