Comments (6)
gfball: I've added a possible solution, plus a unittest that demonstrates the problem (at least on this machine).
The solution passes the unittest, but is probably significantly more expensive. It recurses through a nested structure, finding all the primitive types, converting them to unicode strings then finally sorts the list of all the resulting strings. The ordered list of strings is then fed into md5 to generate the hash.
As an added side effect, cache, merge and analytics will need to be emptied since the new value is not any of the previous possibilities.
from das.
valya: Hmm, you're right. I miss that. But now my fear is that your solution may not work in general case. It rely on a fact that dict will have"key" and "value" and I use genkey in different places. How about this way:
{{{
def genkey(query):
if isinstance(query, dict):
squery = str(query)
lquery = list(squery)
lquery.sort()
query = ''.join(lquery)
keyhash.update(query)
return keyhash.hexdigest()
}}}
I convert query, if it is a dict, into a list, sort the list and create a new string out of it. Seems to work, but I didnt' test with unicode/base strings mixture.
from das.
gfball: Yes, on the way home I realised there were lots of things wrong with it, eg
['a', 'b'] and ['b', 'a']
['abc', 'def'] and ['abcdef']
{'a': 'b'} and {'b': 'a'}
{1: {2: 3}} and 1abac61 2eb6285 2]]
would all compare the same, which is clearly broken.
I think the right way to do this is to do it as genkey() already does (using json.dumps, which deals with unicode issues for us and works fine with everything but dict) but use a subclass of JSONDecoder that represents dict as [(k1, v1), (k2, v2) ...], sorted by key. I think this should have 1) relatively low overhead and 2) doesn't require us to write any recursive code.
from das.
valya: Sounds good to me. Give it a shot and send a patch.
from das.
gfball: Turns out to be really quite simple. If you use JSONEncoder directly, it accepts a kwarg "sort_keys" which resolves this problem without having to even change the dictionary representation. In many cases the qhash will be the same as before.
Had to also make JSONEncoder available in jsonwrapper, since we can only get it from json, not cjson.
from das.
valya: Patch has been applied, closing the ticket.
from das.
Related Issues (20)
- pagination links do not remember DBS instance in DAS2GO HOT 3
- Handling of large run range queries HOT 4
- Duplicate entries in JSON output HOT 2
- Perform final migration of DAS python server to DAS go server HOT 3
- Display of Fraction of Datasets with invalid Files HOT 20
- Given a block name and a run number, query for file names HOT 2
- status filter not working HOT 3
- 'plain' option sometimes misbehaves HOT 3
- DAS not found but by "crab status" it exists HOT 2
- Config files not available from the Configs link in web queries HOT 7
- Error="invalid character 'p' after array element" HOT 14
- "DAS query guide" link points to nowhere HOT 1
- finding the file that contains a run,lumi is not working HOT 6
- error=invalid character '<' looking for beginning of value" HOT 2
- for results format = list, total number of entries is not correct HOT 1
- panic: runtime error from dasgoclient HOT 2
- Turn on Rucio requests from DAS by default HOT 1
- Explore data consistency checking between Rucio and PhEDEx HOT 3
- Remove Rucio-Account header from command line version of DAS HOT 2
- Remove PhEDEx from default list of services to query HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from das.