1) Have a default rule file with rules_1 defined.
2) Import a new rule, change it's ID to rules_1 as well.

The result is that the new rule has overwritten the previous one, instead of creating a new rule (i.e. rules_2).

Comments

mitchell’s picture

Component: Rules Core » Rules Engine

Would switching to machine_names fix this?

fago’s picture

Status: Active » Closed (works as designed)

> 1) Have a default rule file with rules_1 defined.

This namespace is reserved for the rules module and may not be used by other modules.

amitaibu’s picture

Let me explain differently what I mean:
1) User A exports a rule, called rules_1. (i.e. the name given by the system).
2) User B exports a different rule also called rules_1
3) User B import A's rule. Now she imports B's rule. The collision is not treated properly.

amitaibu’s picture

Status: Closed (works as designed) » Active

This of course also happens if I have on the same site different modules implementing hook_rules_defaults() - with the same rule names.

As a work around - I add to my default rules a suffix (i.e. rules_1 >> rules_1_default_config).

fago’s picture

Priority: Critical » Normal

>3) User B import A's rule. Now she imports B's rule. The collision is not treated properly.

Hm, the collision is determined as far the rules have different labels, right? Thus, this enables users to export a rule and to re-import the same rule - maybe in a different version, without having duplicated rules in the system. However, yes if two different rules have unintentionally the same label, one rule is being overwritten.

So when I wrote this I thought it might be useful, however I see that the behaviour might be unexpected. So it's probably better to just create a new rule in any case? Patch welcome!

-> I set down the priority to "normal", as I don't think it's crititical.

amitaibu’s picture

> So it's probably better to just create a new rule in any case?
Not that easy (and this is the reason I think it's critical)

1) I have a default rule called rule_1
2) User adds a new rule and system assigns it rule_1 as well --> this means that the default rule is no overwritten.
3) User exports rules to file - expecting to have two rules, but actually has only one - the newest. The first default rule is now deleted. (and when there are many rules - it's hard to tell if you are missing a rule).

fago’s picture

>1) I have a default rule called rule_1
This is the problem, you may not do so. It's the rules module's namespace. You have to use your module's namespace.

amitaibu’s picture

I see - you mean I need to *manually* add prefix to all exported rules?

I should probably revisit #350881: Make exporting to module easier in that case... :)

fago’s picture

Yep.. :)

fago’s picture

Status: Active » Closed (fixed)

Should be fine now? ;)