Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Creating field with datatype "TEXT" on api causes error #696

Closed
Lapsus opened this issue Jan 14, 2019 · 10 comments
Closed

Creating field with datatype "TEXT" on api causes error #696

Lapsus opened this issue Jan 14, 2019 · 10 comments

Comments

@Lapsus
Copy link
Contributor

Lapsus commented Jan 14, 2019

Bug Report

Steps to Reproduce

  1. Create a new database table with an id column/primary key and a column "position" as longtext. Table should not be managed by Directus yet.
  2. Fetch collection data for the new table via API.
  3. Merge the fetched data to have the collection managed with Directus.
  4. Merge the field definition fetched from the API to make column "position" use the "Map" interface.

Expected Behavior

Collection and fields are created properly, as the collection is now managed, and the fields provide interface information.

Actual Behavior

Error: Code: 403 - field "position" does not support length

Other Context & Screenshots

Other interfaces like status, text or date work well that way. Fetching the collection info via API, modifying the data to make the collection managed and setting the fields to the required interfaces. But it failes for "Map", or "Advanced WYSIWYG".

If length is not used by the longtext datatype, it should either be not provided when fetching collection data or it should be ignored when creating the field. At least in my humble opinion.

Or is this the wrong approach?

@benhaynes benhaynes added the bug Something isn't working label Jan 14, 2019
@Lapsus Lapsus changed the title Creating filed interface "map" on api causes error Creating field with datatype "TEXT" on api causes error Jan 15, 2019
@Lapsus
Copy link
Contributor Author

Lapsus commented Jan 15, 2019

I just provided some more details to reproduce the problem.
If i remove the length attribute before passing the information back it works as expected.
So if the length is not required for the datatype, it should be ignored or removed from the filed when fetching the collection information via the api. (in my humble opinion of course).

@wellingguzman wellingguzman removed the bug Something isn't working label Jan 16, 2019
@wellingguzman
Copy link
Contributor

Hey @Lapsus, this is not a bug, it's a expected behavior. The reason there's an error, it's to warn that no matter the length they provide it won't be useful, we could silently avoid this, but then it could cause issues when the user assumes the length was accepted, when it was actually ignored.

That data is provided as information to let the user know how many character the field takes.

@Lapsus
Copy link
Contributor Author

Lapsus commented Jan 16, 2019

Hmm but it seems quite confusing to me ,if the data structure for the field is different depending on the datatype.

Maybe this is an issue for the documentation then? As far as i have seen, there is no documentation on how the fields have to be defined depending on datatype/interface etc. Or did i miss that? I think i remember having read some note on fields, but no clear definition on what has to be defined or is optional for the different datatypes.

@rijkvanzanten
Copy link
Member

But it failes for "Map", or "Advanced WYSIWYG".

It sounds like my that the application might wrongly send the length value, even though it's not being used. @wellingguzman this might actually be an issue on the application side of things, not the API.

@Lapsus
Copy link
Contributor Author

Lapsus commented Jan 16, 2019

I am fetching and sending back to the API without using the APP.

if that helps. i am creating a setup script that fetches from the collection endpoint and modifies the fetched data to make certain collections managed and to setup the fields according to an external configuration. The modified data structure is then sent back to the API endpoint.

@rijkvanzanten
Copy link
Member

Ahh I see. I think the API might return length: null for those fields, but then throws a warning if you send length: null.

I suppose the API should ignore if length: null is send for TEXT fields. I think it should return the error when a length is provided that something not null, f.e. length: 200 as that implies that the user made a mistake

@benhaynes
Copy link
Sponsor Member

So is this working as expected? Should we update the Docs accordingly and then close this?

@wellingguzman
Copy link
Contributor

It's working as expected, It's a confusion, or missing information what that means. There are some mysql types that doesn't require length, even though some return an actual length, such as TEXT.

Ignoring length can be confusing as well, when the field doesn't even allow it.

I prefer removing the length from these data types than ignoring them when they exists.

@rijkvanzanten
Copy link
Member

But that means that the API won't accept it's own output as it's input. If the API is returning length: null for TEXT type fields, it should accept length: null as input for those fields as well

@wellingguzman
Copy link
Contributor

I believe Input shouldn't reflect output, or be 100% compatible. While the field has length, the length cannot be changeable, that's why is not allowed in the input. returning null could means it has no length.

We can discuss what we can do here to avoid the confusion.

I will close this as this is not a bug nor a feature request.

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

No branches or pull requests

4 participants