Photos intermittently throws exceptions when accessing media items via AppleScript

Originator:bewebste
Number:rdar://20626449 Date Originated:20-Apr-2015 05:09 PM
Status:Open Resolved:
Product:iLife Product Version:Photos 1.0 (209.52.0) OS X 10.10.3 (14D131)
Classification:Serious Bug Reproducible:Sometimes
 
Summary:
When using AppleScript to perform operations on media items in a Photos library, Photos will sometimes return a -10000 error and print out an error message to the console reading:

4/20/15 4:53:28.560 PM Photos[19355]: An exception was thrown during execution of an NSScriptCommand...
4/20/15 4:53:28.560 PM Photos[19355]: *** -[__NSArrayM objectAtIndex:]: index 8388 beyond bounds for empty array

Steps to Reproduce:
There is no method to make the error occur with 100% reliability, but in my testing, the following script will  trigger an error almost every time when working with a test library of 9,200 photos.

tell application "Photos"
	set destinationAlbum to make new album named "Destination Test Album"
	set totalPhotoCount to count of media items
	--Just repeat a bunch of times to try to trigger the error
	repeat with i from 1 to 50
		set aPhoto to media item (random number from 1 to totalPhotoCount)
		add {aPhoto} to destinationAlbum
	end repeat
end tell

The example script is adding a photo to an album, but any number of other commands will give the same problem, e.g. setting a property on the photo, adding keywords, etc. It also happens when using either index or unique ID object specifiers for the media items.

Expected Results:
50 random photos from the library should be added to a new album named "Destination Test Album"

Actual Results:
Eventually, one of the "add" commands will return a -10000 error, with Photos printing out exception info to the console.

Version:
Photos Version 1.0 (209.52.0), OS X 10.10.3 (14D131)

Notes:
The problem definitely appears to be correlated to library size. The greater the number of media items in the Photos library, the more likely Photos is to generate AppleScript errors.

Addendum:
I've been able to boil down the reproduction to an even simpler script:

tell application "Photos"
	repeat with i from 1 to count of media items
		get media item i
	end repeat
end tell

Simply calling the accessors to retrieve object specifiers for the items in the library seems to be enough to reproduce the errors.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!