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

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

Closed
ViktorNacht opened this issue Sep 10, 2018 · 6 comments
Closed

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

ViktorNacht opened this issue Sep 10, 2018 · 6 comments

Comments

@ViktorNacht
Copy link

ViktorNacht commented Sep 10, 2018

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

CREATE TABLE vendors(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_phone varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (vendor_id) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 |

@preaction
Copy link
Owner

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: (50ee597) but thanks for letting me know! It means people are reading the docs 😄

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
Copy link
Author

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 added a commit that referenced this issue Sep 11, 2018
When we aren't given a list of columns we have to try to make one up. If
we then also don't have a field named "id", it is quite possible that
our table will have no columns in it at all. Now, we use the x-id-field
if specified to make sure that we have at least one useful column in the
table.

Thanks @ViktorNacht for reporting this problem

Refs #17
@preaction
Copy link
Owner

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!

preaction added a commit that referenced this issue Sep 11, 2018
    [Fixed]

    - Fixed editor not fetching newly-created item when `x-id-field` is
      set in the collection. Thanks @ViktorNacht for reporting this
      issue! [Github #17]
    - Fixed item list table not showing any columns when `x-id-field` is
      set. Thanks @ViktorNacht for reporting this issue! [Github #17]
    - Fixed docs for the `x-ignore` collection configuration appearing
      under the field configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants