V8-archive: Required status field is saved even though it is empty but data not displayed

Created on 2 Aug 2019  Â·  17Comments  Â·  Source: directus/v8-archive

Bug Report

Steps to Reproduce

  • Fresh install of v2.3.1
  • Create status_test collection without the status field
  • Create status field using the status field type and make it required.
  • Add an item.

Here's screen recording

Expected Behavior

  • There should be an error saying that Status field is required.

Actual Behavior

  • It says Item saved. BUT it is not displayed in the list of items for that collection.

Other Context & Screenshots

The item is actually saved in the database but the status value in db is raf.

image

Here's the field structure:

{
  "type": "status",
  "datatype": "VARCHAR",
  "length": 20,
  "field": "status",
  "interface": "status",
  "default_value": "draft",
  "width": "full",
  "options": {
    "status_mapping": {
      "published": {
        "name": "Published",
        "value": "published",
        "text_color": "white",
        "background_color": "accent",
        "browse_subdued": false,
        "browse_badge": true,
        "soft_delete": false,
        "published": true
      },
      "draft": {
        "name": "Draft",
        "value": "draft",
        "text_color": "white",
        "background_color": "blue-grey-100",
        "browse_subdued": true,
        "browse_badge": true,
        "soft_delete": false,
        "published": false
      },
      "deleted": {
        "name": "Deleted",
        "value": "deleted",
        "text_color": "white",
        "background_color": "red",
        "browse_subdued": true,
        "browse_badge": true,
        "soft_delete": true,
        "published": false
      }
    }
  },
  "required": true
}

Technical Details

  • Device: Desktop
  • OS: Win 10 10.0.18362.145
  • Web Server: Apache/2.4.29
  • PHP Version: PHP 7.1.30
  • Database: 10.1.40
  • Install Method: v2.3.1 build
bug

Most helpful comment

Ugh, this issue has come up before. We need to solve this "trims first/last character" issue once and for all. At least now we know it's likely a MariaDB specific problem.

🔔 @directus/api-team

All 17 comments

Hey @JbalTero

Not able to replicate this. @rijkvanzanten can you please verify this once?

@bjgajjar @rijkvanzanten I'm upgraded now to Spouting Whale — (190807A)

Still the same issue, here's a screenrecording of what happens when I add status field manually.

@JbalTero — I am not able to reproduce this neither in my local nor in the latest release.

Don't know the exact reason, why you are getting this issue at your end! Maybe @rijkvanzanten can help you here.

@bjgajjar I was also able to reproduce this in my remote test server.

Hey @JbalTero — did you try replicating on the Directus demo? That might be useful since it's a shared system. Otherwise, could you send us a database dump to help debug?

@benhaynes it works fine in the Directus Demo, are you using MariaDb in that?

MySQL I believe.

@benhaynes @bjgajjar @rijkvanzanten

I think this isssue is specific in MariaDb, Check my recording.

The field's default value is getting trimmed in its first and last character. In line src/core/Directus/Database/Schema/SchemaManager.php:676

Ugh, this issue has come up before. We need to solve this "trims first/last character" issue once and for all. At least now we know it's likely a MariaDB specific problem.

🔔 @directus/api-team

This issue is gone if you create a collection with status field pre-selected.

@JbalTero

I checked this in MariaDB but still not able to replicate over there :(

@bjgajjar Using MariaDB, did it go inside src/core/Directus/Database/Schema/SchemaManager.php:672?

Yes

@bjgajjar @benhaynes

This issue occurs in Mariadb 10.1, but not on Mariadb 10.2+

It is because the column_default in 10.1 is not quoted, while starting 10.2, column_default is quoted.

Changes & Improvements in MariaDB 10.2

image

That's the reason @bjgajjar was not able to replicate on her side since she is using 10.2, while I'm using 10.1

Closing this as it is not Directus related.

Let's plan on adding a minimum MariaDB version to the docs. If someone wants to submit a PR to fix this we'll review.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andgar2010 picture andgar2010  Â·  3Comments

chintohere picture chintohere  Â·  3Comments

HashemKhalifa picture HashemKhalifa  Â·  3Comments

maettyhawk picture maettyhawk  Â·  3Comments

ondronix picture ondronix  Â·  3Comments