为什么具有多重继承的 DBIx::Class 更新失败?

发布于 2024-09-24 11:46:18 字数 1017 浏览 12 评论 0原文

我有一个 DBIC 模式,其中所有类都使用公共基类和定义类。基类加载公共组件,并重写更新方法以便在审核表中记录变更集。定义类是从数据库生成的静态类。典型的类头看起来像这样:

package Schema::Base;

use base 'DBIx::Class::Core';

sub update {
  my $self = shift;

  # track changes to row

  my $instance = $self->next::method(@_);

  # save changeset to audit table

  return $instance;
}


package Schema::Immutable::User;

use Moose;
use MooseX::NonMoose;
use namespace::autoclean;
extends 'DBIx::Class:Core';

__PACKAGE__->load_components("InflateColumn::DateTime");



package Schema::Mutable::User

use base ('Schema::Base', 'Schema::Immutable::User');

sub update {
  my $self = shift;

  # encrypt password

  return $self->next::method(@_);
}

一切都工作正常,直到我在 User 类中添加和覆盖更新。显然,基类中存在重写,并且用户类以某种方式发生冲突。我正在使用 next::method(@_) 调用下一个更新方法,但它总是挂起。

这是一个 CGI 应用程序。因此,当我点击“保存”时,浏览器会旋转,直到我点击转义键取消请求。此时,我的日志记录重新启动,它显示所有查询都正在正确且快速地执行,但它挂在 User 类的末尾,并且直到我在浏览器中单击转义键后才会继续。

更新:这似乎是与催化剂相互作用的问题。当单独运行时,该代码可以正常工作。但是,当从催化剂应用程序内执行时,它会失败。

I have a DBIC schema, where all the classes use a common base class, and definition class. The base class loads common components, and overrides the update method in order to record changesets in an audit table. The definition class is a static class generated from the database. A typical class header looks something like:

package Schema::Base;

use base 'DBIx::Class::Core';

sub update {
  my $self = shift;

  # track changes to row

  my $instance = $self->next::method(@_);

  # save changeset to audit table

  return $instance;
}


package Schema::Immutable::User;

use Moose;
use MooseX::NonMoose;
use namespace::autoclean;
extends 'DBIx::Class:Core';

__PACKAGE__->load_components("InflateColumn::DateTime");



package Schema::Mutable::User

use base ('Schema::Base', 'Schema::Immutable::User');

sub update {
  my $self = shift;

  # encrypt password

  return $self->next::method(@_);
}

Everything was working fine until I added and an override to the update in the User class. Apparently having the override in the base class, and the User class conflict in some way. I'm using next::method(@_) to call the next update method, but it always hangs.

This is a CGI application. So when I hit "save" the browser spins its wheels until I hit escape to cancel the request. At this point, my logging picks back up and it shows that all the queries are being executed correctly, and quickly, but it hangs at the end of the User class, and does not progress until I hit escape in the browser.

UPDATE: This appears to be an issue with the interaction with catalyst. When run by itself this code works correctly. However, when executed from within a catalyst application it fails.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傾旎 2024-10-01 11:46:19

我在我正在调试的应用程序中发现了这个问题的根本原因。原作者正在创建一个请求解析对象,该对象实例化一个 CGI 对象来解析传入的请求。然而,这与催化剂相冲突,因此请求对象会一直旋转直到客户端的请求结束。显然,他们需要获取的只是 url 和用户的 IP,因此很容易插入代码来使用环境变量来执行此操作,而无需调用 CGI。

I discovered the root cause of this issue in the application I was debugging. The original author was creating a request parsing object that instantiates a CGI object to parse the incoming request. However, this conflicts with catalyst, so the request object spins its wheels until the request from the client ends. Apparently all they needed to get was the url, and the ip from the user so it was easy enough to insert code to do that using the environmental variables without calling CGI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文