Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QuerySelectField works on one server, breaks on another with same code

I'm in the process of setting up a test installation of my current Python/Django project. Everything works great on my dev server, but we recently set up a new VM for the test and eventual production copies of the project. I'm using Python, Django, SqlAlchemy (with a MSSQL backend), and WTForms as my main packages.

I'm having a problem where my test server is not behaving properly. I did not personally set up or install these packages on either server (that was done by someone who is now gone), so I don't really know everything about it all, but I do know that on my test server I've been having a lot of issues I am not having on the dev server. For instance, Django was not properly resolving methods when I used them in templates (it would return 'bound method UserForm.action of... etc' instead of the return value), and now it seems to be typecasting a number of things into integers when they are never declared as such. Versions of python, django, wtforms, sqlalchemy are the same on all servers. Here's the sample code that works fine on the dev server, but breaks on the test server (along with error message):

forms.py:

class NewPracticeForm(wtforms.Form):
    Name = wtforms.TextField("Practice Name", [wtforms.validators.Required()])
    OrgID = safields.QuerySelectField("Organization", pk_attr='OrgID')
    action = '/Admin/H/newpractice/'

pulsedb.py (sqlalch table definition):

#engine created here, can include that if necessary but its just a standard engine=create_engine() using pymssql
Base = declarative_base()
metadata = Base.metadata

class Practice(Base):
    __tablename__ = 'Practice'
    Name        = Column(String(256) , nullable=False)
    OrgID       = Column(String(30) , ForeignKey('dbo.Orglist.OrgID') , nullable=False)

views.py:

def partNewPractice(request):
    context = Context()
    frm = forms.NewPracticeForm()
    frm.OrgID.query = pwdb.session.query(pwdb.OrglistMap)
    context['form'] = frm
    #Return the response here using a method which just tacks a couple things on before returning a normal response

And so, I select an organization from the select field, which posts 'OrgID=Z55' (since the OrgID table uses a 3character string as an ID column), but somewhere along the line this causes a problem. The form points to a handler which does:

services.py

def HandlerAddPractice(request):
    prac = pdb.Practice()
    frm = forms.NewPracticeForm(request.POST, obj=prac)
    frm.OrgID.query = pwdb.session.query(pwdb.OrglistMap)

And that's as far as it gets, because the program throws an error:

invalid literal for int() with base 10: 'Z55'

I've found this also happens on a similar field with a QuerySelectField, where it is trying to convert a UUID into an integer for some reason. Is there a setting somewhere that I'm missing? I was able to work around the method thing, but this is not really something I can ignore and work around at this point. Thanks! Any other code/info available on request. Also, there are lots of other fields, but I left those out in the interest of brevity.

like image 896
Jimmy McCarthy Avatar asked Sep 13 '10 14:09

Jimmy McCarthy


1 Answers

This seems like a deployment issue.

There are basically three ways to deploy django:

  1. system wide install
  2. deploy expanded django directory with your code, import using relative path
  3. using virtualenv

My approach would be to select one of these options (probably 2 or 3, also depending on how you install your other dependencies like SqlAlchemy); then check if there are no conflicts with other deployments.

like image 181
Freek Wiekmeijer Avatar answered Sep 30 '22 04:09

Freek Wiekmeijer