I've been using Services on a project for a while and have had no problems up until yesterday and I have been unable to resolve them. All of a sudden, nodes being submitted through node.save do not contain a uid or name. What's more bizarre is that the accompanying node_revision information and the watchdog entry for the new node DO have the correct user information.

I'm using the JSON server and am not attempting to pass any uid or name entries in the node object I send to the URL; up to this point, Drupal has always filled in the correct information. It suddenly stopped working and I can't think of any changes that have been made to the system. Nodes submitted through the web interface do not exhibit the same problem - only nodes submitted through Services using node.save.

I'm hoping that someone else has seen this issue before and can offer a remedy? Thanks!

Comments

mediabounds’s picture

I went into node_service.inc and added some debug messages around line 168 to determine if the uid was getting set there and it is correctly being set. $edit['uid'] had the correct uid. But by the time hook_insert is called, the uid was 0.

Submitting a node of the exact same type with the web interface does not have this problem. I assume the same hooks would be called in both instances?

Again, I would really appreciate any insight on debugging this issue. Thanks!

mediabounds’s picture

Title: node.save is not setting a uid » node.save should set user name in addition to uid if uid is missing
Version: 6.x-2.4 » 6.x-2.x-dev
Assigned: Unassigned » mediabounds
Status: Active » Needs review
StatusFileSize
new876 bytes

I found the cause of the problem.

The nodes I'm submitting through services do not have their uid's set. I was leaving that up to Drupal and it seemed to be working fine. However, I was messing with permissions yesterday and added the "administer nodes" permission which was when the bug started occurring. It seems that Services has a bug that if a node object is submitted with node.save without a uid and that particular user has the "administer nodes" permission, the node will not be saved with the user's information and here's why:

In node_submit in node.module on line 845, it checks for the administer nodes permission because someone with administer nodes permission can change the author of a post. If the name is not set, it is assumed the post was supposed to be anonymous. Just setting the uid in Services on line 172 in node_service.inc is not enough, you need to also set the username just in case the user has the "administer nodes" permission.

mediabounds’s picture

I thought about it some more and realized that in the check for whether the user provided an author, it should also check for both uid and name so that if the user only specified one field, it wouldn't change the author unexpectedly.

Perhaps there should be an additional check for if the request only provided a uid and no name as the same issue would occur.

gdd’s picture

I hate to be that guy, but why would you be submitting nodes without a uid in the first place?

I am reluctant to add these extra checks, because I like Services to behave exactly as Drupal core does, because then developers know what to expect (even when what you expect is stupid.) The consistency is really important.

mediabounds’s picture

In my case, I don't know the uid.

My application does not use Services to log in because it uses the CAS module to authenticate users with another server. The only information I get following the authentication is the Drupal session ID (and maybe the username). As far as I know, the only way to get a user's information in services is if I already have the uid.

Arguably, this would work just like Drupal core would. Drupal core does not ask for the currently logged in user, it takes the information from the currently logged in user unless the user has the administer nodes permission, in which case it takes the information from the "name" field on the node form. Services handles this incorrectly by not defaulting with the currently logged in user's name in that field like Drupal core does. It attempts to fill in the currently logged in uid but that is not the right way to handle it - it should be the currently logged in username.

I agree the extra checks for if the user only has the UID filled in and not the name are outside of what Drupal core already does and really is not needed; I was just thinking about what happens if the request came in with only a uid as the same issue could occur.

kylebrowning’s picture

Status: Needs review » Closed (won't fix)

2.x is feature frozen, and this doesnt seem to be an issue in 3.x. if you want, create a separate issue to add something along the lines of retrieve user by email.

mediabounds’s picture

It's not a new feature - it is a bug.

The way the 6.x version of the module handles a node submission without a uid is wrong.

stillfinder’s picture

Hi!
You need simple to add username and user's id to node structure. This is example in C# (using xmlrpc):

XmlRpcStruct lgn = drupal.Login(hash, domain, timestamp, nonce, sid, username, pass);

string uid = ((XmlRpcStruct)lgn["user"])["uid"].ToString();
string name = ((XmlRpcStruct)lgn["user"])["name"].ToString();

node["uid"] = uid;
node["name"] = name;

So, you must to send next structure
stdClass Object
(
[nid] => 731
[uid] => 2
[name] => username
........ etc