QuerySelectField在一个服务器上工作,在另一个服务器上使用相同的代码

时间:2023-01-27 23:30:40

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.

我正在设置我当前Python/Django项目的测试安装。在我的dev服务器上,一切都很好,但是我们最近为测试和最终的产品复制创建了一个新的VM。我使用Python、Django、SqlAlchemy(具有MSSQL后端)和WTForms作为我的主要包。

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):

我有一个问题,我的测试服务器没有正常运行。我个人没有设置或安装这些包在服务器(这是由现在的人了),所以我不知道这一切的一切,但我知道,在我的测试服务器我一直有很多问题我没有在开发服务器上。例如,当我在模板中使用方法时,Django没有正确地解析方法(它将返回'bound method UserForm ')。行动……etc'而不是返回值),现在它似乎将一些东西类型转换成整数,而这些东西从来没有被这样声明过。python、django、wtforms和sqlalchemy的版本在所有服务器上都是相同的。下面是在dev服务器上运行良好的示例代码,但是在测试服务器上出现故障(以及错误消息):

forms.py:

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):

pulsedb。py(sqlalch表定义):

#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:

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:

因此,我从select字段中选择一个组织,该字段会发布'OrgID=Z55'(因为OrgID表使用一个3个字符的字符串作为ID列),但是沿着这条线的某个地方会产生问题。表单指向处理程序:

services.py

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.

我发现,这种情况也发生在使用QuerySelectField的类似字段上,因为某些原因,它试图将UUID转换为整数。有没有什么地方我错过了?我可以处理方法的问题,但这并不是我可以忽略的。谢谢!任何其他代码/信息可要求。此外,还有很多其他字段,但为了简洁起见,我省略了这些字段。

1 个解决方案

#1


1  

This seems like a deployment issue.

这似乎是一个部署问题。

There are basically three ways to deploy django:

部署django有三种方法:

  1. system wide install
  2. 系统广泛安装
  3. deploy expanded django directory with your code, import using relative path
  4. 使用代码部署扩展的django目录,使用相对路径导入
  5. using virtualenv
  6. 使用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.

我的方法是选择其中一个选项(可能是2或3,也取决于如何安装其他依赖项,如SqlAlchemy);然后检查是否与其他部署没有冲突。

#1


1  

This seems like a deployment issue.

这似乎是一个部署问题。

There are basically three ways to deploy django:

部署django有三种方法:

  1. system wide install
  2. 系统广泛安装
  3. deploy expanded django directory with your code, import using relative path
  4. 使用代码部署扩展的django目录,使用相对路径导入
  5. using virtualenv
  6. 使用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.

我的方法是选择其中一个选项(可能是2或3,也取决于如何安装其他依赖项,如SqlAlchemy);然后检查是否与其他部署没有冲突。