When I selected "none" for the node pages in the context settings page, I got a website fatal error.

PDOException: SQLSTATE[HY000]: General error: 1364 Field 'selectors' doesn't have a default value: INSERT INTO {statuses_contexts} (type, weight, view) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => og [:db_insert_placeholder_1] => -5 [:db_insert_placeholder_2] => statuses_stream ) in drupal_write_record() (line 6975 of /Users/stalski/Sites/menhir/heartbeat7/includes/common.inc).

Comments

mathankumarc’s picture

I think the problem is there is no default value is set for selectors fields and for pages fields also default value is missing. I dunno whether we have the same problem in D6 also.

This is occurring always(whatever the value you are selecting for any context)

icecreamyou’s picture

This is not an issue in D6. I am also confused as to why this is a problem in D7 since text columns in the database cannot have default values (supplying a default value causes errors in Postgres). Possibly this will need to be resolved by manually supplying a default value, being careful not to overwrite any previously specified value.

To clarify, is this just happening on specific context settings pages like admin/statuses/contexts/user, or is it happening on the general context page at admin/statuses/contexts too?

icecreamyou’s picture

While we're at it, let's add an explanation to the context configuration page about what it does. It seems to confuse a lot of people.

venutip’s picture

Status: Active » Needs review
StatusFileSize
new813 bytes

The error occurs because there is no default value and the column is set to NOT NULL. Removing that restriction on the `selector` and `pages` fields allows you to save and update contexts.

I can't confirm that this makes contexts work as they should, because I'm not sure I understand this feature :) But it resolves the error (uninstall, apply patch, reinstall).

If they're not allowed to be NULL, then they should be marked as required on the form.

icecreamyou’s picture

Status: Needs review » Needs work

#4 is an acceptable solution I think, although the patch needs an update function. Note also:

./includes/utility/statuses.form.inc:64:  $selectors = module_invoke_all('statuses_refresh_selectors', $recipient, $type) + explode("\n", $context['selectors']);
./includes/utility/statuses.admin.inc:400:      '#value' => $context['pages'],

I believe these cases (and possibly one or two others I missed) will cause E_STRICT errors if the value of the relevant property is null. I think that the most consistent solution here would be to manually set the 'selectors' and 'pages' attributes to '' (the empty string) in statuses_determine_context() if the values are null.

7twelve’s picture

StatusFileSize
new1.74 KB

First patch ever, so hopefully I've done this correctly :)

But, here's a patch to set pages and selectors to either an empty string, or a previously defined value as mentioned in #5. Also a small change on the user context views part, as it was looking at the option text rather than the value.

icecreamyou’s picture

Status: Needs work » Fixed

#6 is actually the ideal solution; committed to dev (with minor changes -- removed extra whitespace and redundant parentheses). Thanks!

This exposes another problem which we will address as a follow-up: #1675086: Saving the context configuration form for the first time makes the contexts out of order

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.