This project is archived and is in readonly mode.
Fixtures.identify should generate uniqueIDs
-
Frederick Cheung
I've always wondered whether this was going to be a problem with anyone. Typically the number of things in a fixtures file is quite small, so it does seem quite unlikely unless there are many fixtures.
Fundamentally the problem is that: (as i understand it) we need to be able to generate the label for people(:bob) without having read the people.yml. Perhaps Fixtures.identify could stash away all the ids it has generated so that it knows not to reuse certain values?
-
Frederick Cheung
Another thought: is there any evidence that String#hash is generating particular bad values (ie bad uniformity etc...) ?
-
vlad.zar (at gmail)
String#hash doesn't need to generate unique value, it generates hash and do it pretty well :) Instead, if I see a method named *identify*, I expect unique value to be generated.
I'm used to this nice new feature in edge Rails. It allows me to have easily reading relations in fixtures.
Having a big non sequential IDs for records is also a small advantage in tests. It gives me more realistic data, which looks like application is being in use some years maybe :) I mean Some records were deleted. Btw, I've found a bug in project just because I have such a big IDs.
-
josh
- State changed from new to wontfix
- Tag set to activerecord, bug, fixtures
Fixtures were not mean for HUGE data stores. 1000 records is going slow your tests down a ton since that gets reloaded every test case. Probably not a good idea. I'd use a factory pattern to create this large data set for the tests you need it. I don't think fixture collision tests are necessary.
-
roobnoob
It's really a bad idea to use a hash as a synonym for uniqueness. A collision can happen at any time, whether you have 2 entries or millions. Of course, the probability of a collision with 2 entries is microscopic, but it's there; it's like a mine waiting to be stepped on.
And fixtures aren't just used for testing. They can be used as seed data sources (as you deploy, you run a rake task that loads up the db with seed data from fixtures). Or as mentioned above, to have a bunch of data for stress testing.
Once you get into this realm, you might have millions of rows, and now you're hitting real probabilities of a collision.
There should at least be a big huge disclaimer "WARNING!.." in the foxy fixtures documentation.
Now, as to how to fix the problem, that's a tough one. A brute force solution to load everything in and track id's works, but then you start running into potential memory issues if you store these hashes in memory when dealing with huge data sets.
I would probably leave it as "wontfix", since there are 2 cases: a) either somebody is generating the fixtures by hand and runs into the collision, or b) huge data sets are being generated via some program, as in the above.
For a), just edit the file and change one of the colliding symobls, for b), don't use foxy-fixtures. Since it's being generated by code, simply generate the id as well.