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

UUID field automatically changes to "string" and can't fix it #21635

Open
slyk opened this issue Feb 29, 2024 · 6 comments
Open

UUID field automatically changes to "string" and can't fix it #21635

slyk opened this issue Feb 29, 2024 · 6 comments

Comments

@slyk
Copy link

slyk commented Feb 29, 2024

Describe the Bug

There should be an option to switch back to UUID generation or an alert that this can't be done (when switching first time from uuid to string field). I ended up with >20000 records table that now can't automatically add new items without generating UUID manually.

There are times when need to add some existing uuid of records to the table, but still use generator for times when UUID is empty. So to do this people can just change "On Create" behavior. It changes without any warnings fast and simple. So people hope that switching it back will be just that simple... but that behaviour switching changes the type of the column. And also that type can't be changed back to UUID (while data is the same and nothing is changed).

THE BUG: "type" of the field must not be changed automatically if the user did not changing it manually in type selector.

...or at least let people to switch it back.

To Reproduce

  1. Create UUID field.
  2. Edit field and change "On Create" settings from "Generate UUID" to "Do nothing".
  3. Save field settings.
  4. Open field again and see that we can't switch to "Generate UUID" again. and that is the problem

Directus Version

v10.9.3

Hosting Strategy

Self-Hosted (Custom)

@slyk slyk changed the title UUID field can't allow switch to string and back. UUID field automatically changes to "string" and can't fix it Feb 29, 2024
@slyk
Copy link
Author

slyk commented Mar 1, 2024

Seems like manual changing of the "special" column in directus_fields table for the given field solves the problem. But still its scary when the "type" of column changed without user permission and user can't revert it from admin panel.

@rijkvanzanten
Copy link
Member

@slyk what database are you using?

@paescuj
Copy link
Member

paescuj commented Mar 2, 2024

@rijkvanzanten I could reproduce this with SQLite

@rijkvanzanten
Copy link
Member

Ah, that confirms my suspicion. I was assuming this would be the case for the database types where there is no native UUID, as it has to use a char(36) instead. The data model change update to remove the uuid generating flag then in turn causes the api to think it's just a regular string instead.

@slyk
Copy link
Author

slyk commented Mar 2, 2024

@slyk what database are you using?

Yes its mysql or mariadb.
Yes the field by itself is varchar(36) in database. So in my post is sometimes put "type" in quotes, so its not really a type.

And string is great sometimes. I could have uuids for simple items and some predefined ids for system standard items like "notfound" id for all the times that the item was searched and not found I have this "dummy" object instead of null.

I just want uuid generator to work as needed when we need it :) and if possible put manual string when i need it (but that looks more like feature request not a bug) :)

@paescuj
Copy link
Member

paescuj commented Mar 2, 2024

In the meantime, as an alternative to manually modifying the database, you can update the field via API 1 with the following payload:

{
  "meta": {
    "special": ["uuid"]
  }
}

Footnotes

  1. https://docs.directus.io/reference/system/fields.html#update-a-field

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

No branches or pull requests

4 participants