on 2023 Apr 14 8:06 PM
Hi,
While a custom Cronjob runs, we are getting an error - Error: could not translate value expression 'session.catalogversions'
There are many active search restrictions in the application, whereas this issue is caused by a particular searchRestriction that has below details
Restricted type: DiscountRow
Applies on: CustomerGroup
Filter: ({item:product} IS NOT NULL OR{item:catalogVersion} IS NULL OR {item:catalogVersion} IN (?session.catalogversions))
We are migrating from 2011 to 2205, We have other environments with same code and the restriction in 2011 version, where we do not face this issue. It only occurs in 2205 version.
Session user is admin in RUN AS tab of my cronjob. So since this restriction is on customergroup, it should not be applicable to admin in my understanding.
Any thoughts how can I resolve this without disabling the searchrestriction?
Thanks in advance!
Request clarification before answering.
I found the issue.
In 2205 they introduced a new property
cronjob.ctx.filtered.attributes.in.impex.import.mode=disableRestrictions,disableRestrictionGroupInheritance,use.fast.algorithms,import.mode,disable.attribute.check,disable.interceptor.beans,disable.interceptor.types,disable.UniqueAttributesValidator.for.types,currentCronJob,currentJob,core.types.creation.initial,save.from.service.layer,ctx.enable.fs.on.read-replica,impex.creation
Till 2105, we do not have this property and in cronjob context disableRestrictions attribute is always set to true and restrictions are not applying on cronjobs.
After they introduced this property, the attribute is not set to cronjob context and it takes it as false by default, and the restrictions are not disabled for cronjobs.
Now I have overridden this property in core project.properties as below (removed disableRestriction)
cronjob.ctx.filtered.attributes.in.impex.import.mode=disableRestrictionGroupInheritance,use.fast.algorithms,import.mode,disable.attribute.check,disable.interceptor.beans,disable.interceptor.types,disable.UniqueAttributesValidator.for.types,currentCronJob,currentJob,core.types.creation.initial,save.from.service.layer,ctx.enable.fs.on.read-replica,impex.creation
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please check your cronjob is not multi-threaded and you forgot to set the context to the thread.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is an example of code on how to set the tenant, user and catalog into a new thread.
for (int i=0;i<100;i++) {
executor.execute(new Runnable() {
public void run() {
try {
Registry.setCurrentTenant(currentTenant);
JaloSession.getCurrentSession().activate();
println JaloSession.getCurrentSession().getSessionID();
userService.setCurrentUser(user);
catalogVersionService.setSessionCatalogVersions(catalogVersions);
//put your code here
} finally {
JaloSession.getCurrentSession().close();
Registry.unsetCurrentTenant();
}
}
});
}
Hi Pavan,
You can check your admin user that it should not have any user group which is in hierarchy of customergroup. As you mentioned that restriction which is causing the issue is configured to be applied only on customergroup, it should not be applied to admin if the data setup is correct w.r.t the groups of admin user.
Regards,
Romit Chhabra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi romit.c ,
I found that before making this query, we are doing this for tax calculation purposes userService.setCurrentUser(order.getUser());
So I think it is not an admin user that is why the search restriction in doing its deed.
But I wonder how it worked when we were in v2011, it is the same code.
I tried with below code and it worked:
I would need an evident reason to add this code, what changed between 2011 and 2205 that would need this particular code change. I wonder why session catalog version is not set to the cronjob.
Hi Pavan,To Answer your question specifically .
1)No OOTB Search restrictions are not applied on Admin user as far as i can remember so rest assured this is not happening because of the Search Restrciton.
2)Please check CMSSITEFILTER which sets sites and Catalog version in the session and also check in cron job what is the value of session.catalogversions and if not properly sets then please set it up Properly.
Please also upvote if it helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi deepak.madan, Thanks for your answer.
Catalogversions are set in CmsSiteFilter. But I think this class wont be invoked with cronjob(correct me).
The reason why I talked about the SearchRestriction is, when I disable the search restriction, I am not getting this error.
As far are session attributes of the cronjob are concerned, I can only see 3. Please find the screenshot.
Hi,
You can first check if any of your ctalogVersion is active or not?
Secondly, where the exception is coming in the cronJob you can set Session catalog like below.
sessionService.executeInLocalView(new SessionExecutionBody()
{
@Override
public void executeWithoutResult()
{
commonI18NService.setCurrentCurrency(currency);
catalogVersionService.setSessionCatalogVersion("yourProductCatalog","Online");
}
}, userService.getAdminUser());
Regards,
Saood
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
18 | |
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.