cancel
Showing results for 
Search instead for 
Did you mean: 

Error: could not translate value expression 'session.catalogversions'

pavan-yvs-1
Explorer
0 Kudos
1,452

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!

Accepted Solutions (1)

Accepted Solutions (1)

pavan-yvs-1
Explorer

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

Answers (4)

Answers (4)

YannickRobin
Product and Topic Expert
Product and Topic Expert
0 Kudos

Please check your cronjob is not multi-threaded and you forgot to set the context to the thread.

pavan-yvs-1
Explorer
0 Kudos

Hi yannick.robin ,

Can you please let me know how to do the same. Is it at code level or any property?

Thanks.

YannickRobin
Product and Topic Expert
Product and Topic Expert
0 Kudos

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();
}
}
});
}
romitchhabra
Participant
0 Kudos

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

pavan-yvs-1
Explorer
0 Kudos

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:

if (isEmpty(catalogVersionService.getSessionCatalogVersions())){
catalogVersionService.setSessionCatalogVersion(CATALOG_NAME, CATALOG_VERSION_NAME);
}

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.

deepak_madan
Product and Topic Expert
Product and Topic Expert
0 Kudos

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.

pavan-yvs-1
Explorer
0 Kudos

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.

saood
Participant
0 Kudos

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

pavan-yvs-1
Explorer
0 Kudos

Hi Mohammed,

My doubt is if it is working in 2011, why it is not working on 2205.
I cant see anything in the SAP documentation, I would need a reason to make the change as this is happening during upgrade.

Thanks for your answer.