Objects instantiated via the Plone.API are not showing up in their folder

This was on a brand new install of Plone 5.2.2 on an Ubuntu 20.04 box.

I have some code that I used to load various folders in an automated way...

_path = '/ontology-of-courts/united-states/supreme-court-of-the-united-states'

container = api.portal.get()
container = api.content.get(path=_path)

Now, create the object...

for item in state_sc:
print('Working on ' + item)
obj = api.content.create(type='Folder', title=item, container=container)

Since we are at the command line, we need to commit the object to the database...

transaction.commit()
api.content.transition(obj=obj, transition='submit')
api.content.transition(obj=obj, transition='publish')
transaction.commit()

... which works just fine. All the objects that were created are viewable in the correct folder. However, when I try to insert a hierarchy of objects (folders within folders), none of the new objects are viewable in the standard folder view. I know that the objects were instantiated (because they show up in the catalog, as well as the nav-bar menu). But they don't show up in the folder into which they were instantiated (even when you look at "Contents"). They do show up if you hit manage_main in the respective folder URL's. Here is the nested code for the objects that are instantiated but not visible:

def get_path_section(S = ''):
S = S.lower()
S = S.strip()
S = S.replace(' ', '-')
return S

for i in usca:
# The first element is the Court of Appeals.
# Create that folder object first...
the_path = '/ontology-of-courts/united-states/supreme-court-of-the-united-states'
print('Working on ' + i[0])
container = api.portal.get()
container = api.content.get(path=the_path)
obj = api.content.create(type='Folder', title=i[0], container=container, path=the_path)
# Commit the object to the database, so that we can add the various districts...
transaction.commit()
api.content.transition(obj=obj, transition='submit')
api.content.transition(obj=obj, transition='publish')
transaction.commit()
# the second element is the set of districts.
sub_path = the_path + '/' + get_path_section(i[0])
for j in i[1]:
print('Adding ' + j)
container = api.portal.get()
container = api.content.get(path=sub_path)
obj = api.content.create(type='Folder', title=j, container=container, path=sub_path)
# Commit the new object to the database...
transaction.commit()
api.content.transition(obj=obj, transition='submit')
api.content.transition(obj=obj, transition='publish')
transaction.commit()

Any idea what I might have done wrong?

I have analyzed a similar problem: folder_views did not show items even though there have been items. In my case, it turned out that the catalog search parameters to locate the content have been wrong (due to https://github.com/plone/Products.CMFPlone/issues/3157). In my case, the key to understand the problem has been a ("firefox") network analysis of the request that determines the content. There, I could see that the search parameters have been wrong.

Okay, that makes sense (sadly). The problem is cropping up in folders that weren't loaded via the API. This is a pretty glaring problem, incidentally.

Plone Foundation Code of Conduct