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

get_project_settings of doesn't reflect per-spider settings #2378

Open
mohmad-null opened this issue Nov 5, 2016 · 4 comments
Open

get_project_settings of doesn't reflect per-spider settings #2378

mohmad-null opened this issue Nov 5, 2016 · 4 comments

Comments

@mohmad-null
Copy link

It's possible I'm using this wrong. But I'm doing the following:

class MySpider (Spider)
  def __init__(self):
		custom_settings = {
			'AUTOTHROTTLE_ENABLED': False
		}

  a = scrapy.utils.project.get_project_settings()
  print(a.copy_to_dict())

My settings.py has AUTOTHROTTLE_ENABLED: True.

Based on my reading of https://doc.scrapy.org/en/latest/topics/settings.html#populating-the-settings - the custom_settings value should override the value of settings.py. But the result of the above is:

....
AUTOTHROTTLE_ENABLED: True
...

It's using the value from settings.py - am I misunderstanding this or is it a bug? I was hoping to load and alter settings dynamically during the init.

@IAlwaysBeCoding
Copy link
Contributor

IAlwaysBeCoding commented Nov 6, 2016

You need to put customs_settings as a class attribute, outside your __init__() method because you are setting it up as an instance attribute. The way to use get_project_settings() is so you can load up your settings from settings.py from anywhere in your Scrapy project. When you call that method you are getting all of your settings from your project. In other words, that method does not override any settings at all, it only retrieves your settings from settings.py.

@mohmad-null
Copy link
Author

mohmad-null commented Nov 6, 2016

@IAlwaysBeCoding - Thanks for the correction on custom_settings - I can now see that, looking again at the settings page.

Looking again at the documentation, I can see that the "project settings" is what actually the name for the settings.py settings. Given that, your information does make sense, though the documentation could benefit from spelling that out explicitly.

@redapple
Copy link
Contributor

redapple commented Nov 7, 2016

@mohmad-null
Copy link
Author

@redapple
https://doc.scrapy.org/en/latest/topics/settings.html#populating-the-settings - on that under the "3. Project settings module" bit, I'd probably add a line "get_project_settings can be used to access these settings" - which links to the documentation for get_project_settings

https://doc.scrapy.org/en/latest/topics/practices.html (which seems to be the documentation for "get_project_settings" - it's not documented on either the settings page or the api page) - I'd mention that settings loaded this way are not updated globally (so it can't be used in conjunction with os.environ['SCRAPY_SETTINGS_MODULE'] = 'myproject.settings' within the spider).

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

4 participants