Code

Opened 7 years ago

Closed 7 years ago

#4850 closed (duplicate)

Having a project named "code" breaks things

Reported by: anr@… Owned by: nobody
Component: Core (Management commands) Version:
Severity: Keywords: project name
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

[pequod:/tmp] $ django-admin.py startproject code
[pequod:/tmp] $ cd code
[pequod:/tmp/code] $ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "/usr/lib/python2.5/site-packages/django/core/management.py", line 1672, in execute_manager
    execute_from_command_line(action_mapping, argv)
  File "/usr/lib/python2.5/site-packages/django/core/management.py", line 1563, in execute_from_command_line
    from django.utils import translation
  File "/usr/lib/python2.5/site-packages/django/utils/translation/__init__.py", line 3, in <module>
    if settings.USE_I18N:
  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 28, in __getattr__
    self._import_settings()
  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 55, in _import_settings
    self._target = Settings(settings_module)
  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 83, in __init__
    raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
EnvironmentError: Could not import settings 'code.settings' (Is it on sys.path? Does it have syntax errors?): No module named settings

Attachments (1)

management.diff (491 bytes) - added by Simon G. <dev@…> 7 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 follow-up: Changed 7 years ago by Simon G. <dev@…>

  • Component changed from Uncategorized to django-admin.py
  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from jacob to adrian
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin
  • Version 0.96 deleted

@bug reporter - unfortunately this looks like a python keyword clash (and for the same reason you can't use "django" or "site" or "test"). There's not much we can do about this, and your best option is to use a different name for your project.

@core developers: This patch adds 'code' to the INVALID_PROJECT_NAMES in management.py. However, this may not be the best fix - it may be better to modify the error message instead, or include builtins in the INVALID_PROJECT_NAME check, or to do some better error checking if possible?

Changed 7 years ago by Simon G. <dev@…>

comment:2 in reply to: ↑ 1 Changed 7 years ago by anr@…

Thanks for the comment.

I'm new to Python & Django, so I didn't take a look at the code yet.

Wouldn't it be possible to keep project names in a different namespace, so they won't interfere with reserved words?

Naive example: what about prefixing project names with "proj_" for internal use?

Regards,

--

Adriano

comment:3 Changed 7 years ago by mtredinnick

  • Triage Stage changed from Ready for checkin to Design decision needed

Simon: it's a never-ending arms-race to try and catch all clashes. At the end of the day, standard Python rules apply: package names must be unique. So we have to check every possible importable package name (__builtins___ is of no help there). This will be time-consuming and error-prone as well (it's not future-error-proof once you start installing third-party packages, for example).

I don't know what the right solution is, beyond asking programmers to think like Python programmers. Maybe there's something, but it's never going to be bullet-proof.

comment:4 Changed 7 years ago by Simon G. <dev@…>

Yeah, that's what I thought the case would be. How about modifying the exception to make this a bit more explicit and help debug - e.g.:

raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors? Is it clashing with an existing module called '%s'?): %s" % (self.SETTINGS_MODULE, self.SETTINGS_MODULE, e)

comment:5 Changed 7 years ago by mtredinnick

If we could work out the path the import came from, that would be useful. I'm a bit worried that your change on its own won't necessarily help somebody who gets bitten by this ("how do I check that?").

Improving the error message would be useful, I agree.

comment:6 Changed 7 years ago by Collin Grady <cgrady@…>

Split the settings value on ".", import the module bit of it ([0]) direct, and check module.__file__ ?

comment:7 Changed 7 years ago by Simon G. <dev@…>

#4993 was marked as a duplicate

comment:8 Changed 7 years ago by Simon G. <dev@…>

#5217 is a duplicate and #3475 attempts to patch a similar issue in management.py

comment:9 Changed 7 years ago by webjunkie

so, this here seems to be a duplicate...

comment:10 Changed 7 years ago by PhiR

  • Resolution set to duplicate
  • Status changed from new to closed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.