@@ -143,6 +143,7 @@ def process_advisories(data_source: DataSource, create_vulcodes) -> None:
143
143
for batch in advisory_batches :
144
144
for advisory in batch :
145
145
try :
146
+
146
147
if not advisory .identifier and not create_vulcodes :
147
148
continue
148
149
@@ -154,9 +155,11 @@ def process_advisories(data_source: DataSource, create_vulcodes) -> None:
154
155
reference_id = vuln_ref .reference_id ,
155
156
)
156
157
157
- if vuln_created or not vuln_ref_exists (vuln , vuln_ref .url , vuln_ref .reference_id ):
158
- # A vulnerability reference can't exist if the vulnerability is just created so
159
- # insert it
158
+ if vuln_created or not vuln_ref_exists (
159
+ vuln , vuln_ref .url , vuln_ref .reference_id
160
+ ):
161
+ # A vulnerability reference can't exist if the vulnerability is
162
+ # just created, so insert it
160
163
bulk_create_vuln_refs .add (ref )
161
164
162
165
for purl in chain (advisory .impacted_package_urls , advisory .resolved_package_urls ):
@@ -176,25 +179,27 @@ def process_advisories(data_source: DataSource, create_vulcodes) -> None:
176
179
existing_ref = get_vuln_pkg_refs (vuln , pkg )
177
180
if not existing_ref :
178
181
bulk_create_vuln_pkg_refs .add (pkg_vuln_ref )
179
- # A vulnerability-package relationship does not exist already if either the
180
- # vulnerability or the package is just created.
182
+ # A vulnerability-package relationship does not exist already
183
+ # if either the vulnerability or the package is just created.
181
184
182
185
else :
183
- # insert only if it there is no existing vulnerability-package relationship.
186
+ # insert only if it there is no existing vulnerability-package relationship. # nopep8
184
187
existing_ref = get_vuln_pkg_refs (vuln , pkg )
185
188
if not existing_ref :
186
189
bulk_create_vuln_pkg_refs .add (pkg_vuln_ref )
187
190
188
191
else :
189
192
# This handles conflicts between existing data and obtained data
190
193
if existing_ref [0 ].is_vulnerable != pkg_vuln_ref .is_vulnerable :
191
- handle_conflicts ([existing_ref [0 ], pkg_vuln_ref .to_model_object ()])
194
+ handle_conflicts (
195
+ [existing_ref [0 ], pkg_vuln_ref .to_model_object ()]
196
+ )
192
197
existing_ref .delete ()
198
+
193
199
except Exception :
194
200
# TODO: store error but continue
195
201
logger .error (
196
- f"Failed to process advisory: { advisory !r} :\n "
197
- + traceback .format_exc ()
202
+ f"Failed to process advisory: { advisory !r} :\n " + traceback .format_exc ()
198
203
)
199
204
200
205
models .VulnerabilityReference .objects .bulk_create (
@@ -259,17 +264,20 @@ def _get_or_create_vulnerability(
259
264
advisory : Advisory ,
260
265
) -> Tuple [models .Vulnerability , bool ]:
261
266
262
- vuln , created = models .Vulnerability .objects .get_or_create (identifier = advisory .identifier )
267
+ try :
268
+ vuln , created = models .Vulnerability .objects .get_or_create (identifier = advisory .identifier )
263
269
264
- # Eventually we only want to keep summary from NVD and ignore other descriptions.
265
- if advisory .summary and vuln .summary != advisory .summary :
266
- vuln .summary = advisory .summary
267
- vuln .save ()
270
+ # Eventually we only want to keep summary from NVD and ignore other descriptions.
271
+ if advisory .summary and vuln .summary != advisory .summary :
272
+ vuln .summary = advisory .summary
273
+ vuln .save ()
274
+
275
+ return vuln , created
268
276
269
277
except Exception :
270
278
logger .error (
271
- f"Failed to _get_or_create_vulnerability: { query_kwargs !r} :\n "
272
- + traceback . format_exc () )
279
+ f"Failed to _get_or_create_vulnerability: { query_kwargs !r} :\n " + traceback . format_exc ()
280
+ )
273
281
raise
274
282
275
283
0 commit comments