Coder Social home page Coder Social logo

Comments (4)

meling avatar meling commented on May 30, 2024

@JosteinLindhom To debug this, you will want to look in assignments/assignments_parser.go. Suggest to add the problematic assignment.yml example as a test case to figure out why it isn't providing parse error in the log, ref. Line 30:

err := yaml.Unmarshal(contents, &newAssignment)

(I think my recollection is that this function doesn't return an error for a yaml field (assignmentid) that is missing a corresponding field in the struct. Which is should according to the documentation.)

from quickfeed.

meling avatar meling commented on May 30, 2024

If my recollection mentioned above is correct, then this is really annoying. Would be great if you can confirm this. Moreover, if that is the case, then readTestsRepositoryContent will return partially initialized assignments ([]*qf.Assignment), which may be written to the database. We should prevent "partially" filled assignments from being written to the database.

Regarding the particular issue of having to invoke UpdateAssignments; the database code for this method has always been a bit problematic I think. I suggest to add some more test cases to try to trigger the particular scenario with "partial" assignments, and see if there is a problem with the implementation of said method. It looks like we have only a simple test TestUpdateAssignment for this in gormdb_assignment_test.go.

from quickfeed.

JosteinLindhom avatar JosteinLindhom commented on May 30, 2024

Jotting down my findings after taking a cursory look:

Seems like yaml.Unmarshal(...) returns an error if the field has the incorrect type, e.g. order: "hello".

yaml.UnmarshalStrict(...) will return an error if an included yaml field does not correspond to any struct fields.
However, we include fields such as title and effort for other tooling to generate README.md

As for the issue with UpdateAssignments, I've found these issues with db.UpdateAssignments:

  • If any one assignment does not have Order > 0, the entire transaction is rolled back.

This explains the issue where no assignments were added when assignmentid was used instead of order

return db.conn.Transaction(func(tx *gorm.DB) error {
	for _, v := range assignments {
		if err := check(tx, v); err != nil {
			return err // if any assignment fails the check, rollback and stops processing assignments
		}
		...
	}
}
  • If any one assignment does not already exist, that assignment is created and the function returns.

This explains why I had to invoke the method three times:

return db.conn.Transaction(func(tx *gorm.DB) error {
	for _, v := range assignments {
	        ...
		var assignment qf.Assignment
		if tx.Model(&qf.Assignment{}).FirstOrInit(&assignment,
			&qf.Assignment{
				CourseID: v.CourseID,
				Order:    v.Order,
			},
		).RowsAffected == 0 {
			// Zero rows affected indicates that the assignment does not exist
			return tx.Model(&qf.Assignment{}).Create(v).Error // commits or rolls back transaction. no further assignments processed
		}
		...
	}
}

from quickfeed.

meling avatar meling commented on May 30, 2024

PR #1002 makes the most trivial fix for a bad assignment.yml file, which is the main thing we want to fix here, so that we can more easily discover why and which assignment.yml file failed to parse correctly. We can also avoid multiple assignments in a single transaction, avoiding the other problem.

@JosteinLindhom Can you please add some tests for this stuff. Just commit to the same PR.

PS: Seems like something doesn't like that I used go 1.20 for GitHub workflows... (didn't have time to debug why... I hate workflows.)

from quickfeed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.