Querying brains for upgrade via backend VS via Script

Hello everyone;

I'm trying to fetch all the brains in my site and patch'em with an upgrade.
Here's my problem: when i try to get all the object launching the upgrade from the plone backend everything work fine BUT when i launch the same upgrade with a script the results are completely different.
I'm using these lines of code:

    catalog = context.portal_catalog
    brains = catalog()

the results:

update by script
(Pdb) [brain.getURL() for brain in catalog()]
['http://nohost/myfolder/mysite/en/assets/man', 'http://nohost/myfolder/mysite/it/assets/man', 'http://nohost/myfolder/mysite/de/assets/man', 'http://nohost/myfolder/mysite/fr/assets/man', 'http://nohost/myfolder/mysite/es/recursos/man', 'http://nohost/myfolder/mysite/en/assets/man/rmi', 'http://nohost/myfolder/mysite/it/assets/man/rmi', 'http://nohost/myfolder/mysite/de/assets/man/rmi', 'http://nohost/myfolder/mysite/es/recursos/man/rmi', 'http://nohost/myfolder/mysite/fr/assets/man/rmi']

update by interface
(Pdb) [brain.getURL() for brain in catalog()]
['http://plone.local/myfolder/mysite/en', 'http://plone.local/myfolder/mysite/en/assets', 'http://plone.local/myfolder/mysite/it', 'http://plone.local/myfolder/mysite/it/assets', 'http://plone.local/myfolder/mysite/de', 'http://plone.local/myfolder/mysite/de/assets', 'http://plone.local/myfolder/mysite/es', 'http://plone.local/myfolder/mysite/es/recursos', 'http://plone.local/myfolder/mysite/fr', 'http://plone.local/myfolder/mysite/fr/assets', 'http://plone.local/myfolder/mysite/en/dealer', 'http://plone.local/myfolder/mysite/fr/dealer', 'http://plone.local/myfolder/mysite/de/dealer', 'http://plone.local/myfolder/mysite/it/dealer', 'http://plone.local/myfolder/mysite/es/dealer', 'http://plone.local/myfolder/mysite/en/dealer/application', 'http://plone.local/myfolder/mysite/fr/dealer/application', 'http://plone.local/myfolder/mysite/de/dealer/application', 'http://plone.local/myfolder/mysite/it/dealer/application', 'http://plone.local/myfolder/mysite/es/dealer/application', 'http://plone.local/myfolder/mysite/en/dealer/contents', 'http://plone.local/myfolder/mysite/fr/dealer/contents', 'http://plone.local/myfolder/mysite/de/dealer/contents', 'http://plone.local/myfolder/mysite/it/dealer/contents', 'http://plone.local/myfolder/mysite/es/dealer/contents', 'http://plone.local/myfolder/mysite/en/dealer/contents/istruzione-di-montaggio', 'http://plone.local/myfolder/mysite/fr/dealer/contents/istruzione-di-montaggio', 'http://plone.local/myfolder/mysite/de/dealer/contents/istruzione-di-montaggio', 'http://plone.local/myfolder/mysite/it/dealer/contents/istruzione-di-montaggio', 'http://plone.local/myfolder/mysite/es/dealer/contents/istruzione-di-montaggio', 'http://plone.local/myfolder/mysite/en/dealer/contents/bollettini-tecnici', 'http://plone.local/myfolder/mysite/fr/dealer/contents/bollettini-tecnici', 'http://plone.local/myfolder/mysite/de/dealer/contents/bollettini-tecnici', 'http://plone.local/myfolder/mysite/it/dealer/contents/bollettini-tecnici', 'http://plone.local/myfolder/mysite/es/dealer/contents/bollettini-tecnici', 'http://plone.local/myfolder/mysite/en/dealer/contents/schema-elettrico-e-mappa-parametri', 'http://plone.local/myfolder/mysite/fr/dealer/contents/schema-elettrico-e-mappa-parametri', 'http://plone.local/myfolder/mysite/de/dealer/contents/schema-elettrico-e-mappa-parametri', 'http://plone.local/myfolder/mysite/it/dealer/contents/schema-elettrico-e-mappa-parametri', 'http://plone.local/myfolder/mysite/es/dealer/contents/schema-elettrico-e-mappa-parametri', 'http://plone.local/myfolder/mysite/en/dealer/new-products-after...

can anyone know how to fix my issue?
thanks and have a good and prolific day :smiley:

If you are using a script, ensure that your are working with the rights of a Manager - either by using newSecurityManager() or granting elevated rights using plone.api:

1 Like

If you launch that script from the command line, there's no request information in that environment, so you need to fake it.

1 Like

Pietro Iudici via Plone Community wrote at 2023-9-12 08:28 +0000:

...
I'm trying to fetch all the brains in my site and patch'em with an upgrade.
Here's my problem: when i try to get all the object launching the upgrade from the plone backend everything work fine BUT when i launch the same upgrade with a script the results are completely different.
I'm using these lines of code:

   catalog = context.portal_catalog
   brains = catalog()

The catalog has special API to be used from a non standard (i.e. non Web)
context, e.g. CatalogTool.unrestrictedSearchResults
and AbstractCatalogBrain._unrestrictedGetObject.
Those are the unrestricted variants for CatalogTool.__call__ and
AbstractCatalogBrain.getObject.

1 Like

thanks everyone i finally managed to resolve the issue! :smiley_cat:
i used the api with:

brains = catalog.unrestrictedSearchResults(portal_type='myType', review_state=['state1', 'state2', 'state'])