Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2488 (closed defect: worksforme)

Opened 8 years ago

Last modified 8 years ago

DeprecatedWarning: pylons.h is deprecated: use your project's lib.helpers module directly instead

Reported by: clayg Owned by: percious
Priority: normal Milestone: 2.1
Component: TurboGears Version: 2.1
Severity: normal Keywords: DeprecatedWarning pylons.h lib.helpers
Cc:

Description

I've got a fresh install of TurboGears2-2.1b2, when I do a fresh quickstart project I get a DeprecatedWarning? pylons.h is deprecated: use your project's lib.helpers module directly instead. it goes on to say "import MYPROJ.lib.helpers as h" instead of "from pylons import h" in my projects lib/base.py but of course I haven't touched lib/base.py

Pylons-0.9.7-py2.6.egg/pylons/templating.py:328: DeprecationWarning?: pylons.h is deprecated: use your project's lib.helpers module directly instead. Your lib/helpers.py may require the following additional imports:

from pylons.helpers import log from pylons.i18n import get_lang, set_lang

Use the following in your project's lib/base.py file (and any other module that uses h):

import MYPROJ.lib.helpers as h

(where MYPROJ is the name of your project) instead of:

from pylons import h

globs.update(pylons_globals())

RE: http://trac.turbogears.org/changeset/5894

Change History

comment:1 Changed 8 years ago by percious

  • Milestone changed from __unclassified__ to 2.1rc1

comment:2 Changed 8 years ago by percious

  • Owner set to percious
  • Status changed from new to assigned

comment:3 Changed 8 years ago by percious

  • Status changed from assigned to closed
  • Resolution set to fixed

comment:4 Changed 8 years ago by amol

  • Status changed from closed to reopened
  • Resolution fixed deleted

With last commit of tg-dev helpers seem to be always empty.

This seems due to the fact that config.get('pylons.package') returns a string with package name so

try:
    h = config.get('pylons.package').lib.helpers
except (AttributeError, KeyError):
    h = Bunch()

always ends in the except clause.

h = sys.modules[config.get('pylons.package')].lib.helpers

seems to fix the problem

comment:5 Changed 8 years ago by percious

  • Status changed from reopened to closed
  • Version changed from 2.1 to 2.1rc1
  • Resolution set to fixed

comment:6 Changed 8 years ago by amol

  • Status changed from closed to reopened
  • Version changed from 2.1rc1 to 2.1
  • Resolution fixed deleted
  • Milestone changed from 2.1rc1 to 2.1

I can replicate the problem on an empty virtual environment with a new project

Inside render.py

try:

h = conf.package.lib.helpers

except (AttributeError?, KeyError?):

h = Bunch()

print 'Helpers', h

prints "{}", while switching it to:

try:

h = confpackage?.lib.helpers

except (AttributeError?, KeyError?):

h = Bunch()

print 'Helpers', h

prints "<module 'prova' from '/home/amol/tmp/prova/prova/init.pyc'>"

comment:7 Changed 8 years ago by amol

Sorry, second version should be:

    try:
        h = conf['package'].lib.helpers

    except (AttributeError, KeyError):
        h = Bunch()

    print h

comment:8 Changed 8 years ago by amol

This seems to be caused by the fact that pylons.config._current_obj() is a PylonsConfig? object which inherits from dict and not from Bunch so accepts access only with [] operator

comment:9 Changed 8 years ago by amol

  • Status changed from reopened to closed
  • Resolution set to worksforme

Patch included in tg-dev tip branch

Note: See TracTickets for help on using tickets.