def test_sql_insert_compiler_return_id_attribute(self): """ Regression test for #14019: SQLInsertCompiler.as_sql() failure """ db = router.db_for_write(Party) query = InsertQuery(Party) query.insert_values([Party._meta.fields[0]], [], raw=False) # this line will raise an AttributeError without the accompanying fix query.get_compiler(using=db).as_sql()
def handleRepoWithCounts(self, dbrepo, hgrepo, dbcount, hgcount): """Just check if changesets counts in db and hg are the same """ if dbcount >= hgcount: # nothing to be done self.verbose("%s\tin good shape" % dbrepo.name) return missing = hgcount - dbcount cnt = 0 through = dbrepo.changesets.through using = router.db_for_write(dbrepo.__class__, instance=dbrepo) connection = connections[using] ins = InsertQuery(through) ins.insert_values([(through.repository.field, None), (through.changeset.field, None)]) comp = ins.get_compiler(using) comp.return_id = False sqlinsert, _params = comp.as_sql() self.verbose("%s\t%d missing" % (dbrepo.name, missing)) for revisions in self.chunk(self.nodes(hgrepo)): self.progress() with transaction.commit_on_success(using=using): cs = Changeset.objects.filter(revision__in=revisions) cs = cs.exclude(repositories=dbrepo) csids = list(cs.values_list('id', flat=True)) if not csids: continue vals = [(dbrepo.id, csid) for csid in csids] connection.cursor().executemany(sqlinsert, vals) transaction.set_dirty(using) cnt += len(csids) self.normal("%s\tadded %d changesets" % (dbrepo.name, cnt)) return
def test_fallback_serialization(val): """ Test that the non-gissy fallback point field does actually serialize into a semicolon-separated format even in the SQL level. """ obj = ModelUsingFallback(f=val) query = InsertQuery(ModelUsingFallback) query.insert_values(ModelUsingFallback._meta.get_fields(), [obj]) comp = query.get_compiler(using="default") assert isinstance(comp, SQLInsertCompiler) comp.return_id = True # prevent bulk sql, params = comp.as_sql()[0] assert "60.0;22.0" in params