angus
(Angus McLeod)
2019 年 7 月 11 日午後 11:34
1
There have been multiple bug reports for the events plugin in the last two days that all seem to be type-casting issues with custom fields. The events plugin hasn’t been substantively updated in a few months.
Is the bellow error related to this plugin? (also posted here )
a user created a topic by copy pasting some content from a facebook page; this has crashed the topic iteslf, the category and his activities page. (the rest of the topics and categories of the site remained accessible)
I managed to destroy the topic from the console and everything went back to normal for the user and category.
Is this error related to the mentioned plugin “discourse-events” ?
here follows the errors:
info:
NoMet…
The plugin.rb file casts event_start as an integer:
Topic.register_custom_field_type('event_start', :integer)
The error is being thrown here:
def has_event?
self.custom_fields['event_start']&.nonzero?
end
The error itself follows this format:
NoMethodError (undefined method `nonzero?' for [1563127206, 1563127206]:Array)
As far as I understand register_custom_field_type it should ensure that the custom_field always returns as the defined type (perhaps I’m misunderstanding it).
Looking at the has_custom_fields.rb concern, there have been a few changes in the past week that could have affected this, in particular
committed 05:26PM - 04 Jul 19 UTC
@eviltrout Any thoughts on this?
In case this is indeed the bug causing problems, here I explain the consequences (it may make your site unusable):
This patch seems to work! I can tell that the difference between having this patch or not for us meant having a broken site or a(n apparently) fully functional one.
These were the effects of the bug:
Discourse not rendering to anonymous users beyond the header (totally unusable site).
For registered users, probably non-cached content (i.e. Latest lists) wouldn’t render, and the rest was a hit or miss.
Strangely enough, from three admins two would lose access to the web UI completely while a t…
angus:
The error itself follows this format:
NoMethodError (undefined method `nonzero?' for [1563127206, 1563127206]:Array)
This was a known bug with custom fields.
In very specific conditions, it would save the value multiple times, thus creating an Array, when you only want an Integer.
You can fix this by making sure there’s only 1 row per custom field in the database.
angus
(Angus McLeod)
2019 年 7 月 12 日午前 10:46
4
Yes, it’s cropped up a few times in the past. This latest rash seems to coincide with recent work on the has_custom_fields.rb concern, so there may be something to review there.
This doesn’t fix it, but helps to address it if it arises:
master ← angusmcleod:add_limit_to_custom_field_ordering
closed 01:38PM - 12 Jul 19 UTC
While not likely, it is possible to end up with two rows in a custom field table… with the same related id.
See further: https://meta.discourse.org/t/custom-field-casting-affected-by-recent-update/122746
For example: https://discourse.angusmcleod.com.au/t/events-code-error-500/1254/4
The data will look something like this.
``topic_custom_fields``
| id | topic_id | name | value |
| ------------- | ------------- | ------------- | ------------- |
| 9180 | 62 | event_start | 1563100201 |
| 9179 | 62 | event_start | 1563100201 |
In most respects this eventuality can be handled in a plugin, however there is one place where this causes a cardinality issue that can't be handled in a plugin: ordering by the custom field in a ``TopicQuery``.
This PR adds a LIMIT to the custom field ordering statement in ``TopicQuery`` to handle that eventuality.
sam
(Sam Saffron)
2020 年 1 月 10 日午前 4:07
5
私の一般的なアドバイスとしては、プラグイン作者の方は、制約を適切に強制するために、マイグレーション時に常にインデックスを追加すべきです。実際、現在作成しているプラグインの多くは、絶対に必要な場合を除いてカスタムフィールドを使用せず、推論がはるかに容易なカスタムテーブルの使用を好んでいます。この具体的なケースでは、以下のインデックスが必要です。
create unique index idxStartEvent on topic_custom_fields(topic_id) where name = 'start_event'
コア側で他に何をする必要があるかはっきりしません。カスタムフィールドの刷新を検討したこともありますが、やや懸念があります。一つ検討しているのは、カスタムフィールドから配列サポートを廃止することです。長年にわたり膨大な数の問題を引き起こしているためです。
fzngagan
(Faizaan Gagan)
2020 年 8 月 25 日午前 6:22
6
スレッドを掘り起こして申し訳ありませんが、その条件の一つは、既存の値を更新する際にシンボルインデックス(例:custom_fields[:hello])を使用した場合です。この場合、値が更新されるのではなく、別のフィールドが追加されてしまい、結果として配列が返されてしまいます。これが唯一の条件ではないかと考えられます。
これにより、発生する副作用は確実に修正されるはずです。
master ← fzngagan:custom-fields-issue
merged 01:52PM - 25 Aug 20 UTC
- As discussed here
https://meta.discourse.org/t/inconsistent-behaviour-in-user… updater-class/161360