I think I may have found a bug. I have a Razor script that was working as expected up until I upgraded to 4.9.0. Here's the gyst of it:
Given that I have media structured in "folders", I have a script that just displays the content of a folder. As an example, Let's say I have a folder with an ID of 1000 that has a bunch of children of type "file", typically PDFs.
dynamic currentMedia = Model.MediaById(1000); var items = currentMedia.Children; foreach(var c in items)
{
//do stuff here
}
My understanding is that the script above should allow me to work with each of the children contained in the media node with ID 1000, and prior to upgrading this worked just fine.
Post upgrade, however, the children returned is not consistent in parent nodes. EG: node ID 1000 might have 20 children, but only 1 is returned... a different node might have 10 children and they are all returned correctly. The only consistency is the inconsistency in which the children are returned... meaning that in my example, node ID 1000 will always have 1 children returned (when it should be 20).
I have found that if I go to the problematic media and perform a sort on all of the children in the node, suddenly they all appear using the code example above. This leads me to believe that there may be something wonky going on with how data is being retrieved/stored in the DB.
Of note, I have added two custom attributes to my "file" media type. These attributes are a text string and a multi-text string.
I too had a similar problem. The problem only resolved itself when I re-saved the media item. I suspect that doing so refreshed the cache that MediaById must call instead. I noticed at the time that the record was in the database so it looks like some sort of caching problem but I haven't been able to reproduce further.
dynamic[] children = mediaNode.Children.ToArray();
foreach(var child in children) { //do stuff }
Some differences I noticed between mine and yours. I use Library.MediaById and I declare children as a array. Keep in mind I'm new to razor stuff so this might be useless (hope it's not)
Thanks Sheppe, I used your advice and resorted the media items and that did the trick. But have you heard or been looking into this for the actual reason and how it should be prevented?
Model.MediaById Inconsistency
I think I may have found a bug. I have a Razor script that was working as expected up until I upgraded to 4.9.0. Here's the gyst of it:
Given that I have media structured in "folders", I have a script that just displays the content of a folder. As an example, Let's say I have a folder with an ID of 1000 that has a bunch of children of type "file", typically PDFs.
My understanding is that the script above should allow me to work with each of the children contained in the media node with ID 1000, and prior to upgrading this worked just fine.
Post upgrade, however, the children returned is not consistent in parent nodes. EG: node ID 1000 might have 20 children, but only 1 is returned... a different node might have 10 children and they are all returned correctly. The only consistency is the inconsistency in which the children are returned... meaning that in my example, node ID 1000 will always have 1 children returned (when it should be 20).
I have found that if I go to the problematic media and perform a sort on all of the children in the node, suddenly they all appear using the code example above. This leads me to believe that there may be something wonky going on with how data is being retrieved/stored in the DB.
Of note, I have added two custom attributes to my "file" media type. These attributes are a text string and a multi-text string.
Cheers,
Sheppe
I too had a similar problem. The problem only resolved itself when I re-saved the media item. I suspect that doing so refreshed the cache that MediaById must call instead. I noticed at the time that the record was in the database so it looks like some sort of caching problem but I haven't been able to reproduce further.
Hi,
I have never had that problem but then again I do it a slightly different way, maybe this can help you for future stuff.
dynamic[] children = mediaNode.Children.ToArray();
foreach(var child in children)
{
//do stuff
}
Some differences I noticed between mine and yours. I use Library.MediaById and I declare children as a array. Keep in mind I'm new to razor stuff so this might be useless (hope it's not)
-Brett
Thanks Sheppe, I used your advice and resorted the media items and that did the trick. But have you heard or been looking into this for the actual reason and how it should be prevented?
is working on a reply...