Skip to content
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

Unwanted lookups #10

Open
davedash opened this issue Mar 2, 2011 · 5 comments
Open

Unwanted lookups #10

davedash opened this issue Mar 2, 2011 · 5 comments

Comments

@davedash
Copy link

davedash commented Mar 2, 2011

This happens:

In [22]: product_details.firefox_history_development_releases['4.0b8']
13:04:1299099865 product_details:WARNING Requested product details file firefox_history_development_releases['4 not found! :
/Users/dash/Projects/input/reporter/vendor/src/django-mozilla-product-details/product_details/__init__.py:59

It seems like it shoudl first check to see if 4.0b8 is an item in the dict and then do the lookup.

@fwenzel
Copy link
Member

fwenzel commented Mar 2, 2011

Not sure if that makes sense? If the file you are asking for does not exist, how are we going to know what's in the dict? On the first access to a JSON data file, product_details will load it (and warn if it's not present). From then on, you're working on a regular dict and the file will not be touched again.

@davedash
Copy link
Author

davedash commented Mar 2, 2011

The problem is this:

product_details.firefox_history_development_releases['4.0b8']

got parsed as

Look for

"firefox_history_development_releases['4"

rather than:

Look for:
"product_details.firefox_history_development_releases" and treat it as a dictionary and get me the right key.

So the problem is that it too greedily looks for things after the dot.

[ shouldn't be a part of a filename. it's just asking for trouble.

@fwenzel
Copy link
Member

fwenzel commented Mar 3, 2011

Oh how fun the Python parser can be! The language construct that does this is __getattr__. I hope I am not using it wrong? I have no idea why the parser would possibly think that [ or ' could be part of an attribute name.

https://github.com/fwenzel/django-mozilla-product-details/blob/master/product_details/__init__.py#L54

@fwenzel
Copy link
Member

fwenzel commented Mar 3, 2011

jbalogh suggested using setattr in __init__ to make all existing JSON files actual attributes, and then just use __getattr__ as a fallback for when a JSON file is requested that doesn't exist. We should try that.

@davedash
Copy link
Author

davedash commented Mar 3, 2011

Hmm... yeah that actually makes sense... pre-load the magic.

The aliases could be implemented there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants