回答編集履歴

1

エラー内容について追記

2022/04/09 11:19

投稿

katsuko
katsuko

スコア3471

test CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  公式のドキュメントには、以下のように書かれています。
6
6
  https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#uri-connections
7
+
7
8
 
8
9
  ```python
9
10
  engine = create_engine('sqlite:///' + databese_file + '?check_same_thread=false', convert_unicode=True)
@@ -18,3 +19,42 @@
18
19
 
19
20
  > By default, check_same_thread is True and only the creating thread may use the connection. If set False, the returned connection may be shared across multiple threads. When using multiple threads with the same connection writing operations should be serialized by the user to avoid data corruption.
20
21
 
22
+
23
+ -------------------------------
24
+ エラーを見落としてた。
25
+
26
+ ```
27
+ AttributeError: 'NoneType' object has no attribute 'place'
28
+ ```
29
+
30
+ このようなエラーが出た場合、スタックトレース、いわゆる「どこでエラーが発生したか」という情報も出力されているはずです。
31
+ その情報を元に、エラーメッセージとあわせて自分のソースコード上で「なぜそれが起きるのか」を考えるのがこの手の問題の解決方法になります。
32
+
33
+ 本来ならばどこで起きているか、まではご自身で調べてください、というところですが、今回は特別に…。
34
+
35
+ エラーメッセージは、「`None`のオブジェクトには`place`という属性はありません」という意味です。
36
+ となると、`place`という属性を参照しているところですから、
37
+
38
+ ```python
39
+ suito.place = request.form.get("place")
40
+ ```
41
+
42
+ ではないかと推測されます。(推測なので、あっているかどうかはわかりませんが、その仮定で話を進めると)
43
+ となると、`place`の属性を参照している`suito`が`None`である為にエラーが起きている、と考えられます。
44
+
45
+ では、`suito`はどこで値が設定されているかといえば、
46
+
47
+ ```python
48
+ suito = db_session.query(SuitoContent).filter(SuitoContent.id == id).first()
49
+ ```
50
+
51
+ ですね。
52
+ つまり、`first`メソッドが`None`を返しているようです。
53
+ であれば、`first`メソッドが`None`を返す条件を調べます。
54
+
55
+ https://www.sukerou.com/2018/12/sqlalchemy-onefirst.html
56
+ 上記のサイトによれば、条件が0件の場合に`None`を返すようです。
57
+ ですので、条件にあったデータがない、と考えられます。
58
+ (なんでデータがないか、までは、わかりません)
59
+
60
+