Open bcardi opened 9 years ago
Hey Bob this doesn't look like a bug. You cannot return an array or object from a route. Every route must evaluate to a value type (string, number, boolean, reference, atom, error). If you want to, you can return an array. However you have to wrap the Array inside of an atom.
{ $type: "ref", value: [...] }
Let me ask you this: do you really want to return an entire array all the time? Or would you like to be able to page over it? If you want to return the entire array use an atom, otherwise match a range in the route and page over it.
@mpaulson If this is indeed the issue, we probably need to add a better error message here. Seems like an object or an array where a value type was expected would be a good thing to give a descriptive error message on, similar to the great ones we have for the parser.
Selling points and several other "simple" arrays are not separate entities with key structures that we can reference; thus there is no route for these. They are stored with the product object in the data store (elastic search). To answer your question, yes, we return the entire contents of these arrays.
You mention wrapping the arrays in an atom, can you give more details or provide an example?
Below is an example of the full JSON Product object we read from elastic search. You will see the object contains several simple arrays, which all fail to return as part of the "ProductsById[{keys}][{keys}]" route.
{
"Sku":"ADC BFSM-950",
"LongDescription":"Mesh Fry Basket, Steel, 9 1/2\" Dia x 5 3/4\"",
"ShortDescription":"FRY BSKT,STEEL,9.5\"",
"Status":1,
"VendorId":1573,
"Height":0.8000,
"Length":1.0000,
"Width":1.0000,
"Weight":1.7000,
"Uom":"EA",
"UpcRetail":" ",
"UpcCarton":" ",
"AssemblyRequired":false,
"MadeFromRecycled":false,
"Returnable":true,
"MinOrderQty":1,
"Hazmat":false,
"BrandName":"Adcraft®",
"BrandLogoUrl":"http://cdn.facility.supplies/WebImages/Logos/ADCRAFT_LOGO.JPG",
"BrandWebsiteUrl":"",
"Name":"Adcraft® Fryer Baskets",
"SummarySellingPoint":"Steel mesh fryer basket.",
"SellingPoints":[
"Steel mesh fryer basket.",
"Nickel plated steel.",
"Made to be used when frying with oil."
],
"SellingCopy":{
"Long":"This round wire fry basket is ideal for light to heavily-breaded food products. This basket can handle the most rigorous of conditions. It can dive right into the fryer and create something delicious. It is nickel-plated to resist corrosion and is easy to clean.",
"Short":"This round wire fry basket is ideal for light to heavily-breaded food products. This basket can handle the most rigorous of conditions. It can dive right into the fryer and create something delicious. It is nickel-plated to resist corrosion and is easy to clean.",
"Medium":"This round wire fry basket is ideal for light to heavily-breaded food products. This basket can handle the most rigorous of conditions. It can dive right into the fryer and create something delicious. It is nickel-plated to resist corrosion and is easy to clean.",
"Catalog":""
},
"Keywords":[
"Fry Basket",
"Steel",
"Storage",
"Cooking",
"Baking",
"Breakrooms",
"Chefs",
"Cookery",
"Culinary",
"Kitchens",
"Packages",
"Restaurants"
],
"PackageIncludes":[
"Includes one basket."
],
"Thumbnails":[
],
"SmallImages":[
],
"LargeImages":[
],
"Videos":[
],
"Attributes":[
{
"Name":"Global Product Type",
"Value":"Cookware-Fryer Basket"
},
{
"Name":"Cookware Type",
"Value":"Mesh Fry Basket"
},
{
"Name":"Material(s)",
"Value":"Steel"
},
{
"Name":"Color(s)",
"Value":"Silver"
},
{
"Name":"Handle Material",
"Value":"Steel"
},
{
"Name":"Diameter",
"Value":"9 1/2\""
},
{
"Name":"Height",
"Value":"5 3/4\""
}
]
}
When I say wrap arrays and objects in atoms I mean this:
{ route: "ProductsById[{integers:numbers}].Thumbnails", (pathSet) => // lets say it's just one integer (5) { jsong: { ProductsById: { 5: { Thumbnails: { $type: "atom", value: [ // actual thumbnails ] } } } } }
Is that clear? I just mean take each array and wrap it inside of an Atom.
Sent from my iPad
On Jun 14, 2015, at 8:47 PM, Bob Cardenas notifications@github.com wrote:
Selling points and several other "simple" arrays are not separate entities with key structures that we can reference; thus there is no route for these. They are stored with the product object in the data store (elastic search). To answer your question, yes, we return the entire contents of these arrays.
You mention wrapping the arrays in an atom, can you give more details or provide an example?
Below is an example of the full JSON Product object we read from elastic search. You will see the object contains several simple arrays, which all fail to return as part of the "ProductsById[{keys}][{keys}]" route.
{
"Sku":"ADC BFSM-950", "LongDescription":"Mesh Fry Basket, Steel, 9 1/2\" Dia x 5 3/4\"", "ShortDescription":"FRY BSKT,STEEL,9.5\"", "Status":1, "VendorId":1573, "Height":0.8000, "Length":1.0000, "Width":1.0000, "Weight":1.7000, "Uom":"EA", "UpcRetail":" ", "UpcCarton":" ", "AssemblyRequired":false, "MadeFromRecycled":false, "Returnable":true, "MinOrderQty":1, "Hazmat":false, "BrandName":"Adcraft®", "BrandLogoUrl":"http://cdn.facility.supplies/WebImages/Logos/ADCRAFT_LOGO.JPG", "BrandWebsiteUrl":"", "Name":"Adcraft® Fryer Baskets", "SummarySellingPoint":"Steel mesh fryer basket.", "SellingPoints":[
"Steel mesh fryer basket.", "Nickel plated steel.", "Made to be used when frying with oil." ], "SellingCopy":{
"Long":"This round wire fry basket is ideal for light to heavily-breaded food products. This basket can handle the most rigorous of conditions. It can dive right into the fryer and create something delicious. It is nickel-plated to resist corrosion and is easy to clean.", "Short":"This round wire fry basket is ideal for light to heavily-breaded food products. This basket can handle the most rigorous of conditions. It can dive right into the fryer and create something delicious. It is nickel-plated to resist corrosion and is easy to clean.", "Medium":"This round wire fry basket is ideal for light to heavily-breaded food products. This basket can handle the most rigorous of conditions. It can dive right into the fryer and create something delicious. It is nickel-plated to resist corrosion and is easy to clean.", "Catalog":"" }, "Keywords":[
"Fry Basket", "Steel", "Storage", "Cooking", "Baking", "Breakrooms", "Chefs", "Cookery", "Culinary", "Kitchens", "Packages", "Restaurants" ], "PackageIncludes":[
"Includes one basket." ], "Thumbnails":[], "SmallImages":[
], "LargeImages":[
], "Videos":[
], "Attributes":[
{
"Name":"Global Product Type", "Value":"Cookware-Fryer Basket" }, {
"Name":"Cookware Type", "Value":"Mesh Fry Basket" }, {
"Name":"Material(s)", "Value":"Steel" }, {
"Name":"Color(s)", "Value":"Silver" }, {
"Name":"Handle Material", "Value":"Steel" }, {
"Name":"Diameter", "Value":"9 1/2\"" }, {
"Name":"Height", "Value":"5 3/4\"" } ] } — Reply to this email directly or view it on GitHub.
@jhusain is this resolved?
Thanks @jhusain $type: "atom" helped
@bcardi, I had the same problem, here's decision: https://gist.github.com/designeng/f00de5e04f27773eaf5c#file-itemsrouter_improved-js-L1-L20 Thanks @jhusain
@jhusain, +1 for a better error message. Otherwise we have MaxRetryExceededError.
When the jsong response includes arrays, the router mistakenly converts these to undefined atoms. I have created a test to demonstrate the issue. I wanted input from the team before submitting a pull request with my test.
When I run the test, it fails as shown below.