Applescript bug in create project leading to incosistent database state?

I am using applescript to create projects and it shows up fine in the UI but is leading to an inconsistent database, which “File > Rebuild database…” fixes.

I am on 4.8.4 (v185.2.0)

My applescript:

set theProject to (make new project with properties {{name: "hello"}} at end of projects of myFolder)

This results in a new project in the correct folder, but if I later select it and get its id using the applescript below, that id cannot be used in URLs, such as omnifocus:///project/. HOWEVER, that id is “correct” in that if I “File > Rebuild database…”, that non-functional URL begins working.

tell application "OmniFocus"
    tell content of first document window of front document
        set theSel to (selected trees where class of its value is not item and class of its value is not folder)
        set theTasksSelected to {}
        repeat with theItem in theSel
            set the end of theTasksSelected to id of value of theItem
        end repeat
    end tell
end tell

Additional info:

In the database, when everything is good, in the table ProjectInfo, task is always equal to pk. After that applescript, for this entry, the pk is wrong, but rebuilding database fixes it.