Skip to content

GPMONGODB-306: Dynamic attribute only stored once for similar instances of a domain #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
graemerocher opened this issue Jul 3, 2013 · 3 comments

Comments

@graemerocher
Copy link
Contributor

Original Reporter: saphira
Environment: Windows 7 64bits, Grails 2.2.1
Version: 1.3.0.GA
Migrated From: http://jira.grails.org/browse/GPMONGODB-306

When I try to store two Domain instances that only differ in the _id and a date property, the dynamic attribute is only stored in the first instance but not in the second one.

I've created a simple test with my domains to show the problem

{code}
void testAddDynamicProperty(){
setup:
def metadata = ["language":"java"]
Behaviour behaviour = Behaviour.list([max:1]).first()
User user = User.list([max:1]).first()
when:
UserBehaviour userBehaviour = new UserBehaviour(user:user,behaviour:behaviour,site:site,points:behaviour.points,date:new Date())
metadata.each{key,value->
userBehaviour."metadata${key}" = value
}
UserBehaviour userBehaviour2 = new UserBehaviour(user:user,behaviour:behaviour,site:site,points:behaviour.points,date:new Date())
metadata.each{key,value->
userBehaviour2."metadata${key}" = value
}
boolean valid1 = userBehaviour.save()
boolean valid2 = userBehaviour2.save()
then:
valid1 == true
valid2 == true
userBehaviour.metadatalanguage == "java"
userBehaviour2.metadatalanguage == "java"
}

{code}
And this is the result of executing that test

{code}
Condition not satisfied: userBehaviour2.metadatalanguage == "java" | | | | null false net.ds.gamigune.domain.activity.UserBehaviour(behaviour:net.ds.gamigune.domain.Behaviour(id:51d5196ac6c3c3a11664e0b9, namedId:b1, name:b1, hint:null, points:0, maxPerDay:0, maxPerSite:0, minInterval:0, active:true, hidden:false, icon:null, triggerEvents:[:]), site:net.ds.gamigune.domain.Site(id:51d5196ac6c3c3a11664e0af, privateKey:123, publicKey:456, name:site, description:null), points:0)
junit.framework.AssertionFailedError: Condition not satisfied:

userBehaviour2.metadatalanguage == "java"
| | |
| null false
net.ds.gamigune.domain.activity.UserBehaviour(behaviour:net.ds.gamigune.domain.Behaviour(id:51d5196ac6c3c3a11664e0b9, namedId:b1, name:b1, hint:null, points:0, maxPerDay:0, maxPerSite:0, minInterval:0, active:true, hidden:false, icon:null, triggerEvents:[:]), site:net.ds.gamigune.domain.Site(id:51d5196ac6c3c3a11664e0af, privateKey:123, publicKey:456, name:site, description:null), points:0)

at gamigune.test.integration.service.AchievementServiceSpec.testAddDynamicProperty(AchievementServiceSpec.groovy:524)

System output
java
null
{code}

@graemerocher
Copy link
Contributor Author

saphira said:
I've found a workaround, it works if I save the object first and then update it adding the dynamic attributes, but I still think that there's something odd with the behaviour described in the issue...

@graemerocher
Copy link
Contributor Author

arunkytg said:

@graemerocher
Copy link
Contributor Author

arunkytg said:
Please ignore my previous comment. It's a testcase issue for me.

@graemerocher graemerocher self-assigned this May 27, 2015
jdaugherty pushed a commit to jdaugherty/grails-data-mapping that referenced this issue Jan 16, 2025
jamesfredley pushed a commit that referenced this issue Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant