preaction / Yancy

The Best Web Framework Deserves the Best Content Management System
http://preaction.me/yancy/
Other
54 stars 21 forks source link

Routed to "undefined" collection item when adding new items #17

Closed ViktorNacht closed 6 years ago

ViktorNacht commented 6 years ago

When creating new collection items I receive the following output from Morbo:

`[Mon Sep 10 10:34:36 2018] [debug] POST "/yancy/api/vendors" (8622a8f9)

[Mon Sep 10 10:34:36 2018] [debug] Routing to controller "Yancy::Controller::Yancy::API" and action "add_item"

[Mon Sep 10 10:34:36 2018] [debug] 201 Created (0.007491s, 133.494/s)

[Mon Sep 10 10:34:36 2018] [debug] GET "/yancy/api/vendors/undefined" (03f60b91)

[Mon Sep 10 10:34:36 2018] [debug] Routing to controller "Yancy::Controller::Yancy::API" and action "get_item"

[Mon Sep 10 10:34:36 2018] [warn] OpenAPI >>> GET /yancy/api/vendors/undefined [{"message":"Missing property.","path":"\/vendor_address"},{"message":"Missing property.","path":"\/vendor_name"},{"message":"Missing property.","path":"\/vendor_phone"}]

[Mon Sep 10 10:34:36 2018] [debug] 500 Internal Server Error (0.002883s, 346.861/s) `

I'm using a very minimal test config:

plugin Yancy => { backend => 'mysql://***', read_schema => 1, collections => { vendors => { title => 'Vendors', 'x-list-columns' => [qw(vendor_name vendor_address)], 'x-id-field' => 'vendor_id' } } }; I sincerely apologize if this is a configuration issue, but as far as I can tell, it should just work.

Updating and deleting work fine.

preaction commented 6 years ago

Your configuration looks fine. This is definitely a bug.

My guess right now is that the MySQL backend isn't correctly finding the ID after the row is created. Could you post the SHOW CREATE TABLE vendors output from MySQL? That will help me diagnose this issue.

Also, are you upgraded to the latest version of Yancy? There was a bug fixed in v1.005 where the editor would show new items as "undefined" instead of the real data. That would probably make the log look like that.

ViktorNacht commented 6 years ago

Just want to add a couple more things:

When you use read_schema without any collection config Yancy doesn't display any fields at all unless you use x-list-columns. Not sure if this is the intended behavior.

Also x-ignore under Extended Field Configuration references collections instead of fields.

ViktorNacht commented 6 years ago

CREATE TABLEvendors( vendor_idint(11) unsigned NOT NULL AUTO_INCREMENT, vendor_typeenum('food','goods','services') NOT NULL DEFAULT 'food', vendor_namevarchar(255) NOT NULL DEFAULT '', vendor_addressvarchar(255) NOT NULL DEFAULT '', vendor_phonevarchar(255) NOT NULL DEFAULT '', PRIMARY KEY (vendor_id) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 |

preaction commented 6 years ago

Right now, read_schema without any x-list-columns tries to pick some fields based on their name matching some exact strings. I don't really have a better idea: If the field it picks is too long, it destroys the table, or it could show sensitive information accidentally. Maybe it could always try to use the x-id-field in the list if the list is not specified at least, and if only the ID field is available, it could say "Hey, configure x-list-columns to get more fields in this table" or something.

The x-ignore documentation just got fixed the other day: (https://github.com/preaction/Yancy/commit/50ee597254eda755b31e1d57f4d21d1e08bc0150) but thanks for letting me know! It means people are reading the docs :smile:

Thanks for posting the table schema. I'll run some tests and see what I come up with. Might be a week or so.

ViktorNacht commented 6 years ago

Awesome, thank you. Yancy really is an amazing piece of work, there's nothing else like it (drop-in database management). I also love it because it's a very quick way to include Bootstrap, jQuery and Font Awesome in my project. FYI, I"m using "$VERSION = '1.007';"

preaction commented 6 years ago

Okay, I think I've fixed this problem: It was an issue with setting x-id-field for any collection, but as you noticed it was only in the editor (the data was still written).

I've also updated the default x-list-columns to always include the x-id-field, so hopefully there won't be a situation where there are no columns in the table (which makes for a useless editor).

Once Travis-CI tells me it's okay, I'll release v1.008. Thanks for the help in fixing this issue!